Topic: TRY, CATCH (no guarantee!?)


Author: "Morten Rasmussen" <mra@mail1.stofanet.dk>
Date: 1999/09/27
Raw View
I have read that CATCH not with guarantee catches alle exceptions, can it be
true!?

Please look at the code below. I have mad a DLL that containt X functions,
when I distribute my DLL, I would like that the users can return an
errorcode (alle code shall bee in try-catch) if anything went wrong.
I don't care which type of error, I just want to know which part of the
DLL-code there have coursed the problem/error.
Bus I am not satisfied if catch not catches ALL errors! If I have a division
by zero or if I index an array at -35 (ex.) my catch is   nt called. Why?

double functionX
{
   try
   {
      /* Some code heer */
   }
   catch(...)  /* also tried with 'catch(const exception &error) */
   {
      return = -1010; /* Errorcode */
   }
}

If my code does   nt work, I would be greatfull, if someone can give me at
little code eksemple. Please.

Thank you, if you can help me with my problem.

Morten Rasmussen



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/09/27
Raw View
In article <7so2lv$atv$1@news101.telia.com>, Morten Rasmussen
<mra@mail1.stofanet.dk> writes
>Bus I am not satisfied if catch not catches ALL errors! If I have a divi=
sion
>by zero or if I index an array at -35 (ex.) my catch is=B4nt called. Why=
?
>
>double functionX
>{
>   try
>   {
>      /* Some code heer */
>   }
>   catch(...)  /* also tried with 'catch(const exception &error) */

This catches all program generated C++ exceptions.  However divide by
zero is likely to be a system level exception.  Whether a system level
exception can somehow be converted into a C++ exception depends on the
implementation.=20


>   {
>      return =3D -1010; /* Errorcode */

Your function is defined to return a double.  returning this as an error
code would seem to be problematic.  Indeed, in general, returning a mix
of error code and legitimate values is often a poor design decision.  It
only works if there really are values that can never be generated as
part of the normal evaluation.  Floating types are particularly
dangerous as error codes because of the well-known floating point
problems with comparison for equality.

>   }
>}
>
>If my code does=B4nt work, I would be greatfull, if someone can give me =
at
>little code eksemple. Please.
>
>Thank you, if you can help me with my problem.

Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]