This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]