exceptions in C++
Matthias Oltmanns
Mathias.Oltmanns.Oltmanns@sysde.eads.net
Wed Mar 26 10:21:00 GMT 2003
Hi John,
many good ideas but i'm dreaming of a more general solution. The divide
by zero was an example for situations, where the runtime-environment
signals errors by "signals" instead by exceptions. I would like to see
a general solution, where i'm able to deal only with exceptions. Other
situations are segmentation faults, bus erros etc.
Is it possible to catch these errors and to continue in the program flow
without the need of termination?
cu
Matthias
Am Die, 2003-03-25 um 18.24 schrieb John Love-Jensen:
> Hi Matthias,
>
> How about this...
>
> try {
> if(denominator == 0)
> throw DivideByZeroException();
> int a = numerator / denominator;
> } catch (DivideByZeroException err) {
> ...
> }
>
> Or this macro-magic function hiding...
>
> #define DIV(_r, _n, _d) \
> if(_d == 0) throw DivideByZeroException(); \
> _r = _n / _d;
>
> Or this preferred inline equivalent...
>
> template <typename T>
> inline T Divide(T n, T d) {
> if(d == 0) throw DivideByZeroException();
> return n / d;
> }
>
> > As an example by providing a signal handler which is capable to raise
> exceptions.
>
> I believe you cannot throw exceptions through a signal handler, because
> you'd be throwing an exception across a C-barrier.
>
> --Eljay
--
Matthias Oltmanns
Tel: 04421-1543-274
mail: Mathias.Oltmanns.Oltmanns@sysde.eads.net
More information about the Gcc-help
mailing list