问题
When failing to catch a subclass of Exception
, Eclipse will issue a compilation warning (red).
However, when an subclass of Error
is uncaught, no warning is issued, making it easy to forget including the throws SomethingError
statement.
回答1:
This is the difference between checked (subclasses of Exception excluding RuntimeException) and unchecked exceptions (subclasses of RuntimeException or Error).
- Oracle note on the subject
- Stackoverflow: Java: checked vs unchecked exception explaination
回答2:
This is essentially to avoid having to add exception handling code to every trivial line of code that you write. This question explains that really well: Why are Runtime Exceptions "unchecked" in Java?
来源:https://stackoverflow.com/questions/12162572/eclipse-warn-about-uncaught-error