help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ exceptions


From: Detlef Vollmann
Subject: Re: C++ exceptions
Date: Sat, 24 Jul 2004 12:12:38 +0200

Hans Aberg wrote:

> class CLoop : public DConstruct
> {
> public:
>   ...
>   class Object : public DGeneric
>   {
>   public:
>     Data iter;    // Iteration expression
>     ...
>     Data generic(Data&);
>   };
> };
> 
> Data CLoop::Object::generic(Data& da)
> {
>   try {
> again:
>     for (;;)
>       iter(da);
>   }
>   catch (CBreak::Object& dret) {
>     return dret.data(da);
>   }
>   catch (DContinue&) {
>     goto again;
>   }
> 
>   return new DEmpty;
> }
> 
> Here, if the data argument of this evaluator throws a DContinue object, the
> dynamic effect in the loop is the same as a C/C++ static "continue". And,
> similarly, a thrown CBreak::Object causes a dynamic loop break.
Yes, C++ exceptions are essentially the (required) replacement
for the C longjmp mechanism.

Unfortunately, the implementation of exception are generally
optimized for the no-throw case, i.e. it is assumed the throwing
an exception is really an exceptional case and in that case a
higher overhead for actually throwing an exception is accepted
for a lower overhead in the no-throw case.

Detlef

-- 
Detlef Vollmann   vollmann engineering gmbh
Linux and C++ for Embedded Systems    http://www.vollmann.ch/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]