The Right Approach to Exceptions

deadalnix deadalnix at gmail.com
Sun Feb 19 04:42:19 PST 2012


Le 19/02/2012 02:43, Ben Davis a écrit :
> On 19/02/2012 00:48, Jonathan M Davis wrote:
>> On Saturday, February 18, 2012 16:46:43 H. S. Teoh wrote:
>>> I can't believe something this simple has to be explained so
>>> elaborately. I thought all of us here knew how to use OO??
>>
>> I think that the problem stems from people frequently using exceptions
>> incorrectly, and many of the C++ programmers probably haven't _ever_
>> seen them
>> used correctly, since I don't think that it's very common for C++
>> programs to
>> define exception hierarchies - especially not advanced ones like Java
>> has. And
>> when you see a lot of bad exception code, that tends to turn you off
>> to them,
>> and it definitely doesn't show you how to use them correctly.
>>
>> - Jonathan M Davis
>
> I can assure you they get misused in Java too. Most people write this:
>
> try {
> lots and lots and lots of stuff here
> }
> catch (Exception e) {}
>

You raise 2 prblems of java exception system.

First, RuntimeException is a subclass of Exception. Second, you have to 
catch all Exceptions except RuntimeException and Error.

We can consider what is good in Java without keeping the bad part.


More information about the Digitalmars-d mailing list