On 2009-09-25 01:43, Alan W. Irwin wrote:

> 
> That transfer of control part, is the part I didn't understand.  Although I
> have very little C++ experience you got me interested enough to look at a
> C++ tutorial on exceptions
> (http://www.deitel.com/articles/cplusplus_tutorials/20060325/), but that
> didn't really answer my question either.  If you throw an exception many
> routine calls deep in the code does control immediately jump to the catch
> block after the try block in the calling code or is all the intervening
> function processing and returning involved (which would then necessarily
> call exit)?
> 
> I guess from what you have said, the answer to that rhetorical question must
> be "immediate jump", but there must be a very special mechanism to make the
> code block code location available to _all_ code (no matter how many routine
> calls are used to get to that code) which _might_ throw an exception.
> 
> I was well aware Python had exception handling, but I never thought too much
> until now about the machine code practicalities involved in the code jump
> involved (and skipping all intervening code) in transferring control in a
> different way than the normal function return mechanism when an exception
> has been thrown.
> 

If I understand these matters correctly, then the stack is unwound until
a function is encountered that does want to take care of the exception.
(At the very least this is what happens in Java. I am not too sure about
C++, but I think it works there in the same way.) Once an exception is
thrown, the clean-up code for a function must come into action to get
rid of the local variables that can no longer exist (this includes 
finalising objects).

As an exception is "just" a way of stepping out of a function at a more
or less arbitrary point, the program must be able to catch it and
continue its execution. It is therefore important that everything is
properly cleaned up.

In other words, exception handling is not a trivial matter and not all
programming languages we support support them.

Regards,

Arjen



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to