FAQ

Java

JSP

Servlet


Advertisement



How Can I Catch All Possible Exceptions in Java?

All exceptions come from the "mother class" called java.lang.Throwable and one of two subclasses called java.lang.Error and java.lang.Exception. A block of code that is executed when an exception occurs is called an Exception handler. By catching java.lang.Throwable, it is possible to handle all unexpected conditions.

...
try {
}
catch(Throwable e) {
...
}
...

There are some special exceptions that used by the JVM, those are the sub-classes of java.lang.Error. We are not suppose the catch them in our real code and we usually catch java.lang.Exception for all application and runtime exceptions.

...
try {
}
catch(Exception e) {
...
}
...


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |