Re: [AD] 4.3 error handling

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2006-06-08, Chris <chris.kcat@xxxxxxxxxx> wrote:
> On Thursday 08 June 2006 11:59, Robert Ohannessian wrote:
> > So, C "exceptions" using setjmp don't really work like C++ exceptions,
> > have lots of gotchas, don't interoperate and (to make them work
> > correctly) complicate the user code much more than just checking for
> > return values.
> 
> They don't have many gotchas. al_try must be followed by al_catch, and don't 
> prematurely leave a try block (for which a function could be added, or 
> basically an existing function renamed and publicised). What's so bad?

If you think setjmp/longjmp don't have many gotchas, I'd tend to think
you've not used them much.

Here's another example: longjmps may not restore all local variables.
This is not in my copy of the man pages any more, but it used to be
there and presumably some compilers still have this restriction.  Every
local variable which could be referenced after a longjmp must be
declared volatile.

> And I'd say it makes user code much simpler. Having to check return values 
> makes it much harder because you gotta know which ones can error, what the 
> failure value is,

I have nothing against making return values consistent.

> Given that, the question shouldn't be "why use it?", it should be "why not use 
> it?", IMO. I'm willing to believe there could be a problem with this method, 
> which is why I brought it up for discussion and have been trying to get many 
> opiinions on it, but so far, the only real problem cases brought up are 
> caused by user error.

You might say the same of users not checking return values.

> This helps newbies by providing nicer information for uncaught errors (no 
> more 'why is Windows closing my program and saying "the address can't 
> be 'read'"?'), it helps users that like it by allowing them to use a familiar 
> method, and with both of that, it still allows you to use the method of 
> checking return values, if you wish.

I can't believe you think longjmping is more familiar or easier for
newbies.

> Because I think it's a good idea and most of the concerns people are putting 
> up are either rare cases that were sloppily coded,

It's the rare cases that need the most thought.  Avoiding problems due
to "sloppy coding" by not encouraging them in the first place is part of
good design.  cf. strncpy() which may or may not null-terminate.

Peter





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/