try...catch slooowness?

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 22 05:54:31 PST 2010


On Tue, 21 Dec 2010 17:25:09 -0500, Rob <rob2970 at yah00.com> wrote:

> Steven Schveighoffer wrote:
>
>> An exception is a recoverable error,
>
> Not necessarily. At some point, all the handling options could have been
> tried but all failed in which case there is nothing left to do except for
> letting something higher up (like the operating system) deal with the
> situation. In such a case, recovery did not occur if you consider
> recovery to mean that the program keeps running normally.

In D, unrecoverable errors derive from Error, recoverable ones derive from  
Exception.

By 'recovery' I mean that the program can either continue to run or decide  
proactively to do something different (like print an error and exit).  But  
control is still in the programmer's hands.

>> Exception handling is
>> great when it exists at a much higher level, because you can
>> essentially do all error handling in one spot, and simply write code
>> without worrying about error codes.
>
> That sounds like the common misconception that leads to weak designs.

So you tell me, what is a good design with exceptions?  Because it seems  
like doing:

try fn()
catch(Exception) {...}

is pretty ugly and cumbersome (and clearly has performance issues), when  
it could be:

if(fn() != 0)
   ...

To me, if you are surrounding a single low-level call with an exception  
handler, your design has issues.

-Steve


More information about the Digitalmars-d mailing list