Re: [AD] 4.3 error handling

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


On 2006-06-05, Chris <chris.kcat@xxxxxxxxxx> wrote:
> On Monday 05 June 2006 07:02, Elias Pschernig wrote:
> > I think, for C code, those #defines are really ugly.. at least to me
> > they do look ugly. If I wanted to use #2, then I would use C++, not C.
> 
> But Allegro doesn't use C++. Since Allegro is going to use C (AFAIK), or at 
> least expose a C-only API, it wouldn't be able to properly throw real 
> exceptions.
> 
> Besides, with the way that code is, you can use any of the three at any time. 
> Don't want to use the try/catch defines? Then just call 
> al_error_disable_throws() once at the beginning of your program and don't 
> think anything of them (just be sure to check for failure return codes). Too 
> lazy to do your own error checking? Leave throws enabled and don't worry 
> about the try and catch defines.
> 
> There's many times I wish I could just execute a string of commands and not 
> have to check the return code of each one individually.

Then you should use another language.  Please, keep it out of a C
library.  Imagine if every API reinvented its own (inferior) exceptions.
Even if they all make it optional, it's a total mess.

> A C++ wrapper could still raise real exceptions:
> 
> al_audio::init()
> {
>    al_error_try {
>       driver = al_audio_init_driver(NULL);
>    }
>    al_error_catch {
>       throw al_get_last_error();
>    }
> }
> 
> That also has the benefit of leaving the real throwing in C++, so you needn't 
> have to worry about C++ exceptions through C.

A C++ wrapper (or whatever) would be simpler and more efficient by
just checking return values.

Peter





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