3 ms·
So add a 'throws' clause to the method in which you call the code that throws the checked exception and it will propagate upward.
by Sandman 15y ago
So add a 'throws' clause to the method in which you call the code that throws the checked exception and it will propagate upward.
- samuel 15y ago...or rethrow it as an unchecked exception(RuntimeException).
- brlewis 15y agoYes, this! The most irritating debugging I've had to do in Java code is when someone catches an exception, but fails to handle it effectively, resulting in another exception being thrown later. If you don't know how to handle it effectively, just add the 'throws' clause. It's less typing than try/catch, so I don't understand why people choose to make extra work for themselves and for me. I see a lot of comments here that seem to assume catching the exception is the only option.
- davedx 15y agoExactly. In Eclipse it's so ridiculously easy to make the method pass it on by adding the throw to your method. I find checked exceptions really useful every day :)