Catch all exceptions in Java
class IsNullException extends RuntimeException { }
class IsEmptyException extends RuntimeException { }
static void throwWhenNullOrEmpty(int[] array)
{
if (array == null) {
throw new IsNullException();
}
if (array.length == 0) {
throw new IsEmptyException();
}
}
try {
throwWhenNullOrEmpty(null);
}
catch (Exception e) {
System.out.println("Error happened");
}
- Log in to post comments