Because catching Exception
is very general, how will you know if it’s ArrayIndexOutOfBoundsException
or NullPointerException
? What if you want to handle each one differently?
Example:
try {
veryComplicatedLogic();
} catch(Exception e) {
// null pointer? out of bounds? custom exception?
}
It’s very bad practice to catch an Exception
, try to keep your scope as small as possible and be specific as much as you can.