E. Robert Tisdale wrote:
Steven T. Hatton wrote:
What language first introduced the idea of throwing, catching, and
unwinding.
Fortran.
"The alternate RETURN allows a procedure to return
to one of the several labelled statenebts in the calling program unit
dependent upon the value of an integer variable."
As regards C++, which was the overall topic of my post, I must say there are
many aspects of Lisp error handling combined with catch and throw that seem
to clearly indicate a common origin. Even the concept of RAII seems to be
present. There are differences, but I am specifically interested in what
influences contributed to C++'s exception handling mechanism. Here is a
list of similarities I've noticed between Lisp and C++ regarding C++'s
exception handling.
The use of catch and throw. Note that in Lisp these are not intended
primarily for error handling, but they have clear similarities with the
error handling mechanism.
The use of error symbols is very similar to the use of exceptions in C++.
* Error symbols are arranged in a hirearchie with 'error' at the root. This
is analogous to the derivation hirearchie in the Standard Library.
* Error symbols carry with them a string intended for printing human
readable messages. This is analogous to the string returned by
std::exception::what() in C++
* Error symbols are passed up the call stack to until they encounter a
handler that accepts their type. Clearly analogous to the C++ mechanism of
using multiple catch() statements.
* If no handler is encountered, the process is terminated.
As the forms are exited, all local variable are unbound.
Though technically more similar to Java's finally than C++'s destructor, the
'unwind-project' 'cleanup-forms' serve an analogous purpose. To use C++
terminology, they ensure the essential invariants are preserved: " The
unwind-protect construct is essential whenever you temporarily put a data
structure in an inconsistent state; it permits you to make the data
consistent again in the event of an error or throw."
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell