4

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

Example:

try {
    .... } catch (ex) {     }
Nick Fortescue
  • 43,045
  • 26
  • 106
  • 134

2 Answers2

5

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
  • 22,116
  • 12
  • 58
  • 95
2

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
  • 62,186
  • 18
  • 105
  • 157
  • 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 Oct 23 '08 at 19:34
  • Then the answer is, "Throwable" catches everything. I thought that would be more clear from my answer. – Bill K Oct 23 '08 at 20:10