throw in depth

What I meant recently with "Never use throw-declaration in C++" is following:

int throwing(int i) throw (exception_A)
{
  if(i > 0)
    throw exception_B;
  return i;
}

When compiling on ie. AIX no error is shown during compiling, but if the exception_B gets ever thrown, it magically converts into an uncatchable unknown_exception and crashes your app. I'm not sure if Linux also makes it uncatchable, but there are also no signs of dangers there during compiling.

Microsoft's Visual Studio ships around this elegantly: It just ignores any throw()-declaration everywhere.

I understand why no compiler enforces this to be correct, because of compatibility with old code and huge catch-statements with bad exception-derivates, but I don't know why no compiler has even an option to enforce the correctness of throw-declarations. This would save many people much headache when porting software between platforms.

|

Similar entries