Re: [AD] 4.3 error handling

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


On Wednesday 07 June 2006 22:03, Peter Wang wrote:
> Any way you do it, it's not really *optional*, not if you want to write
> Allegro code that works in all circumstances.

It's never fully optional when you're working with someone else's code. If you 
aren't the only one handling Allegro's state, you have to play nice with the 
other developers. That's just how things work.

> How so?  API1 and API2 are different libraries, not two functions of the
> same library.  They each #define their own setjmp-based try-catch macros
> which don't know about each other.

API1 has to know about API2 to be able to use API2.  And in knowing API2, it 
should know how to handle its errors. Whether it's checking a return value, 
or catching an exception, or whatever.

> > otherwise you shouldn't be using API2 from within API1 (you should not
> > use something you don't know how to handle properly).
>
> So the user can't use the two libraries together?

No, they can. But you have to handle API2 properly. Just like normally you 
wouldn't call api2() and not check its return value, with this you shouldn't 
call api2() without knowing how it'll react on error. And if you can call 
api2(), you can call api2_disable_throws() or api2_try, whichever tickles 
your fancy.

> > I mean, you use atexit() in
> > Allegro because that's how libc handles extra calls for cleanup when it
> > exits. You don't say "well, it was libc that caused the exit, so we
> > couldn't clean up".
>
> I don't understand.

Allegro (API 1) uses libc (API 2). When libc (API 2) errors in Allegro (API 
1), it has to be prepared for it. This can be checking the function's return 
value, then cleaning up as needed (like with using open() to create a 
PACKFILE), or setting up atexit handlers so it'll clean up properly if it 
quits unexpectedly (like with assert).

Now assume, for the sake of argument, Allegro (API 1) used libstdc++ (API 2). 
Allegro calls new, which throws an exception if there's not enough memory. 
Allegro can't ignore the exception if it needs to handle the error and run 
cleanup code, right? So just like Allegro would need to handle libstdc++'s 
possible exceptions, API1 would need to handle API2's possible exceptions. 
Just that C++ uses try/catch, and API2 uses try2/catch2.




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