help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to exit out of a function ? what is try-catch-throw in terms of


From: David Thompson
Subject: Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter
Date: Sun, 04 Nov 2007 23:02:22 GMT

On Sun, 21 Oct 2007 00:55:53 +0200, "Alf P. Steinbach"
<alfps@start.no> wrote:

> * gnuist006@gmail.com:

> > NOTE: I am really afraid of try-catch-throw. I have never been
> > able to understand it since it does not exist in C and I cant
> > really visualize the construct in terms of C. <snip>
> 
> The closest equivalent in C would be a 'longjmp'.  However, a C++ 
> exception is more limited, in that it will only jump up the call chain, 

C longjmp/setjmp also is only guaranteed to work up the stack; the
fact that _some_ implementations can work cross-stack and in
particular cross-thread is not standard nor portable.

> and it's more powerful, in that it will destroy local objects as it does 
> so.  Also, if you use 'longjmp' in C++ you're practically doomed (unless 
> you use it to jump between co-routines with their own stacks), because 
> 'longjmp' doesn't destroy local objects.
> 
Actually it's Undefined Behavior; a good quality C++ implementation
CAN coordinate longjmp, and also pthreads cancellation, with
exceptions to destruct locals cleanly -- but it's not required.

- formerly david.thompson1 || achar(64) || worldnet.att.net


reply via email to

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