'Is it good practice to catch exception or do a null check for Arrays.copyOf

Here is the code snippet :

myObject[] array = Arrays.copyOf(original, original.length, myObject[].class);

Is it okay to catch exception instead of checking original against null?



Solution 1:[1]

Checking for null is more performant than throwing an exception.

Solution 2:[2]

Checking If (value == null) advantages against exception block

  1. Better Performance
  2. More clean
  3. Less code

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael
Solution 2 Samet ÖZTOPRAK