Re: [AD] 4.3 error handling

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


On Wednesday 07 June 2006 17:14, Peter Wang wrote:
> On 2006-06-05, Chris <chris.kcat@xxxxxxxxxx> wrote:
> > 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.

Surely I'd keep it to C++ if I could, but this won't work if Allegro itself 
isn't C++:

try {
   al_init();

   try {
      al_more_code();
   }
   catch(AL_ERROR err) {
      foo();
   }
}
catch(AL_ERROR err) {
   bar();
}

What I'd have to do is check the return values of each thing manually (which 
is my main issue here), and throw. Unless you'd expect me to do something 
like this:

try {
   if(al_init() || al_something_else() || al_another_thing())
      throw al_get_error();

   handle_those_functions_effects();

   try {
      if(al_another_func() || al_yet_another_func() || al_and_another())
         throw al_get_error();
   }
   catch(AL_ERROR err) {
      foo();
   }

   something_else();
}
catch(AL_ERROR err) {
   bar();
}

Which is uglier than any "hack" I'd willingly come up with and use.

> Imagine if every API reinvented its own (inferior) exceptions. 
> Even if they all make it optional, it's a total mess.

If it's optional, you don't have to use it. It wouldn't effect your code at 
all.

When people want to use (some of) C++'s features, and you refuse to move from 
C, you shouldn't be surprised that people try to find ways to get similar 
functionality in the limits they're given. And I don't think this is all that 
bad since it fits in well with what setjmp/longjmp do. It's not really that 
different that what Allegro's doing with vtables. Structures filled with 
function pointers that clearly emulate C++ class member virtual functions. 
They work though, so there's no real problem with them.

(To note, I'm not saying this should move to C++. I'm just saying don't be 
surprised when people start trying out clever "tricks" to get added 
functionality. And when such "tricks" work, I don't really see a problem with 
using them)




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