简体   繁体   中英

Beanshell catch(ex): Exception or Throwable?

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

Example:

try {
    .... } catch (ex) {     }

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());
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM