This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: exceptions in C++
- From: John Love-Jensen <eljay at adobe dot com>
- To: Matthias Oltmanns <Mathias dot Oltmanns dot Oltmanns at sysde dot eads dot net>, <gcc-help at gcc dot gnu dot org>
- Date: Tue, 25 Mar 2003 11:24:48 -0600
- Subject: Re: exceptions in C++
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