From 7768481976280307336
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e445fe05b100a0aa
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-08-23 03:25:05 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: Alexander Terekhov <terekhov@web.de>
Newsgroups: comp.std.c++
Subject: Re: C++ exception handling
Date: 23 Aug 2002 10:25:04 GMT
Organization: IBM Global Services North -- Burlington, Vermont, USA
Lines: 212
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3D651682.32FF2472@web.de>
References: <20020802141846.59203.qmail@web9902.mail.yahoo.com> <_2S29.267$a01.33863850@newssvr13.news.prodigy.com> <1028797052.3258.0.nnrp-13.3e31ffea@news.demon.co.uk> <3D54EE8E.DCE1A08D@iobox.com> <1029750082.26799.0.nnrp-10.3e31ffea@news.demon.co.uk> <3D628B51.35E8C851@iobox.com>
Reply-To: terekhov@web.de
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Delivered-To: std-c++@ncar.ucar.edu
X-Trace: news.btv.ibm.com 1030035049 12584 9.14.4.66 (22 Aug 2002 16:50:49 GMT)
X-Complaints-To: news@btv.ibm.com
NNTP-Posting-Date: 22 Aug 2002 16:50:49 GMT
X-Accept-Language: en
X-MailScanner: PASSED (v1.2.2 27322 g7MGp6pG055638 mailbox2.ucsd.edu)
Xref: archiver1.google.com comp.std.c++:13351


"Sergey P. Derevyago" wrote:
[...]
> >     T sqrt(T t) { if (t<0) throw std::logic_error; else return t.sqrt(); }

Hello my lovely std::logic_error! ;-)

> >     ...
> >     T r = sqrt(+6); // can't throw
> >
> > (This case is easy, but proving that sqrt's argument is non-negative is
> > generally a hard problem.)
>         Imagine: there is no spoo^H^H^Hilver bullet. In those rare cases where we
> know that something() doesn't really throw we can/must use empty try/catch
> blocks:
> 
>  try { something(); }
>  catch(...) {}  // ignore

Now image that something() would throw STACK OVERFLOW, or something 
like that. Do you REALLY want "catch(...) {}  // ignore" it?!

http://groups.google.com/groups?selm=3D6275AE.78E6DF99%40web.de
("Subject: Re: extern "C" and exception handling....", c.l.c++)

"....
 http://www.testdrive.compaq.com
 http://tru64unix.compaq.com/docs/base_doc/DOCUMENTATION/V51A_PDF/ARH9RBTE.PDF

 ----

 spe207.testdrive.compaq.com> what /shlib/libpthread.so|grep DECthreads
          DECthreads version V3.18-138 May 12 2002
 spe207.testdrive.compaq.com> cc -pthread -o seh seh.c
 spe207.testdrive.compaq.com> ./seh

 Go...

 Hi There! Greetings from the ``yellow zone.''

 Exception: Attempted stack overflow was detected (dce / thd)

 Indeed. ;-)

 spe207.testdrive.compaq.com> cat seh.c

 #include <stdio.h>
 #include <memory.h>
 #include <pthread.h>
 #include <pthread_exception.h>
 
 void operation()
 {
   char buffer[128];
   memset( buffer, 0, sizeof( buffer ) );
   operation();
 }

 void* my_thread( void* p )
 {
   TRY {
     printf( "\nGo...\n\n" );
     operation();
   }
   CATCH_ALL {
     printf( "Hi There! Greetings from the ``yellow zone.''\n\n" );
     pthread_exc_report_np( THIS_CATCH );
     TRY {
       RERAISE;
     }
     CATCH( pthread_stackovf_e ) {
       printf( "\nIndeed. ;-)\n\n" );
     } ENDTRY
   }
   ENDTRY
   return NULL;
 }

 int main()
 {
   pthread_t tid;
   pthread_create( &tid, NULL, &my_thread, NULL );
   pthread_exit( NULL );
 }

 spe207.testdrive.compaq.com> cc -pthread -c -o seh2c.o seh2c.c
 spe207.testdrive.compaq.com> cxx -pthread -o seh2 seh2cpp.cpp seh2c.o
 spe207.testdrive.compaq.com> ./seh2

 C++ try...

 Go...

 Hi There! Greetings from the ``yellow zone.''

 Exception: Attempted stack overflow was detected (dce / thd)

 Indeed. ;-)  Ha! >>RERAISE<<

 C++ catch(...)

 Finished!

 spe207.testdrive.compaq.com> cat seh2c.c

 #include <stdio.h>
 #include <memory.h>
 #include <pthread.h>
 #include <pthread_exception.h>

 void operation()
 {
   char buffer[128];
   memset( buffer, 0, sizeof( buffer ) );
   operation();
 }

 void go()
 {
   TRY {
     printf( "\nGo...\n\n" );
     operation();
   }
   CATCH_ALL {
     printf( "Hi There! Greetings from the ``yellow zone.''\n\n" );
     pthread_exc_report_np( THIS_CATCH );
     TRY {
       RERAISE;
     }
     CATCH( pthread_stackovf_e ) {
       printf( "\nIndeed. ;-)  Ha! >>RERAISE<<\n\n" );
       RERAISE;
     } ENDTRY
   } ENDTRY
 }


 spe207.testdrive.compaq.com> cat seh2cpp.cpp

 #include <pthread.h>

 #include <iostream>
 using namespace std;

 extern "C" void go();

 extern "C" void* my_thread( void* p )
 {
   cout << "\nC++ try..." << endl;
   try {
     go();
   }
   catch(...) {
     cout << "C++ catch(...)" << endl;
   }
   cout << "\nFinished!\n" << endl;
   return 0;
 }

 int main()
 {
   pthread_t tid;
   pthread_create( &tid, 0, &my_thread, 0 );
   pthread_exit( 0 );
 }

 spe207.testdrive.compaq.com>

 ...."

< Forward Inline >

-------- Original Message --------
Message-ID: <3D6507EB.EF0B0CF9@web.de>
Date: Thu, 22 Aug 2002 17:48:59 +0200
From: Alexander Terekhov <terekhov@web.de>
Newsgroups: comp.lang.c++.moderated
Subject: Re: A better C++ finite state machine framework

"Sergey P. Derevyago" wrote:
> 
> David Abrahams wrote:
> > Maybe. Once a "return" statement is executed the programmer is usually not
> > so explicitly aware of the destructors that execute on the way out of the
> > function. Nor is she commonly explicitly aware of all destructors that
> > execute when "falling off the end" of a void-returning function... and these
> > are precisely the same paths that execute when an exception is thrown. No
> > more, no less.
> 
>         Sorry, Dave, but you've again made an inaccurate statement: destructors are
> allowed to throw during return, ....

Unless they have "throw()"-nothing exception specifications (ES):

http://lists.boost.org/MailArchives/boost/msg34061.php
(Subject: [boost] Re: Attempting resolution of Threads & Exceptions Issue)

and, never mind that the way how ES are specified in the current 
C++ language is, well, IMNSHO somewhat "flawed":

http://lists.boost.org/MailArchives/boost/msg34239.php
(Subject: [boost] Re: Attempting resolution of Threads & Exceptions Issue)

regards,
alexander.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]



