views:

672

answers:

2

What type of exception is caught by the beanshell catch(ex): Exception or Throwable?.

Example:

try {
    .... } catch (ex) {     }
+2  A: 

Throwable is a superclass (essentially) of Exception--anything that Exception catches will also be caught by Throwable. In general usage they are the same, you rarely (if ever) see other throwable types.

Bill K
True, but does not answer the question. It could be rare but, what happens in the beanshell case if the code throws a Throwable that is not an Exception in the try block ?
Guido
Then the answer is, "Throwable" catches everything. I thought that would be more clear from my answer.
Bill K
+4  A: 

That loosely typed catch will catch everything "Throwable." That will include Errors, Exceptions and their myriad children. You can easily confirm this with:

try {
  new Throwable("Something Exceptional");
} catch (ex) {
  System.err.println(ex.getMessage());
}
Bob Cross