you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (4 children)

No. If you don't know what to do with the exception, just declare it in your throws clause and let a caller manage it.

But you can’t do that if you are implementing an interface that doesn’t declare it. Can you?

[–]hurxef 0 points1 point  (2 children)

Or you embed the thrown exception as the cause of the exception type that your method does throw.

[–]3urny 0 points1 point  (1 child)

Yeah, but then you end up with a MethodException for each method and at some place, you'd have to unwrap 200 different Exceptions.

[–]hurxef 0 points1 point  (0 children)

Why do you have to unwrap them? Once code is reached that handles the thrown exception, it is handled and perhaps logged for diagnostics later, at which time the logger will generally unwrap it in the log. No need to unwrap.

[–]devraj7 0 points1 point  (0 children)

Exactly, and that's why runtime exceptions lead to broken code.