Reputation: 19
I would like to know how is it possible to disable unchecked exceptions in Java and instead print out an error to the console and skip to the very next method in the class where the exception was thrown from.
Upvotes: 0
Views: 89
Reputation: 15445
Reviewing the JVM Specification, 2.10. Exceptions:
An exception in the Java Virtual Machine is represented by an instance of the class Throwable or one of its subclasses. Throwing an exception results in an immediate nonlocal transfer of control from the point where the exception was thrown.
In other words, no matter what you do, any Exception
thrown results in a control transfer, not allowing you to continue as if it never happened.
Upvotes: 2
Reputation: 73568
There's no On Error Resume Next
(or whatever it is) like in Visual Basic. If there's an error, it needs to be handled somehow, not just automatically assume that a program will work properly.
A full suite of unit tests is a good way to check that common unchecked exceptions like null pointers or ArrayIndexOutOfBoundsExceptions
don't occur.
Upvotes: 1