throwable

Differences between Exception and Error

╄→гoц情女王★ 提交于 2019-11-26 11:00:49
I'm trying to learn more about basic Java and the different types of Throwables, can someone let me know the differences between Exceptions and Errors? Errors should not be caught or handled (except in the rarest of cases). Exceptions are the bread and butter of exception handling. The Javadoc explains it well: An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. Look at a few of the subclasses of Error , taking some of their JavaDoc comments: AnnotationFormatError - Thrown when the

Is it a bad practice to catch Throwable?

非 Y 不嫁゛ 提交于 2019-11-26 01:39:27
问题 Is it a bad practice to catch Throwable ? For example something like this: try { // Some code } catch(Throwable e) { // handle the exception } Is this a bad practice or we should be as specific as possible? 回答1: You need to be as specific as possible. Otherwise unforeseen bugs might creep away this way. Besides, Throwable covers Error as well and that's usually no point of return. You don't want to catch/handle that, you want your program to die immediately so that you can fix it properly.