What's the best way to find out which exceptions may be thrown ?

Luis luis.panadero at gmail.com
Wed Jun 3 07:19:45 UTC 2020


On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote:
>
> Could you please elaborate why checked exceptions are more 
> annoying?
>


Have like 3 functions : A calls B, B calls C .

Imagine that now you need to throw a checked exception on C, that 
before wasn't necessary.
You need to add the annoying "throws X" to A and B. And A and B 
could be on another module or on a different project. Perhaps, 
the guy that wrote B, was previsor, and putted "throws Exception" 
(or another generic Exception derived class) on B to avoid 
problems, but now you have loss the information about the 
specific Exception that C throws. So again, the compiler can't 
know what kind of exception could be throwed by A beyond of a 
generic "Exception" (or another generic exception class). Another 
workaround, could be wrapping the C throwed exception by a 
generic exception on B.

I work daily with Java, and it's pretty annoying. That the IDE 
helps you auto putting the throws or suggesting a try/catch, 
helps. But we ended making some generic exceptions 
RuntimeExceptions to avoiding the noise and problems that could 
give checked exceptions.




More information about the Digitalmars-d-learn mailing list