[J3] Exception handling reference

William Clodius w.clodius at icloud.com
Tue Sep 4 10:14:47 EDT 2018


Herb Sutter’s criticism of the C++ exception system identifies three general 
categories of problems. First arbitrary types of objects can be thrown. As a 
result, the thrown objects cannot be placed on the stack and run time type type
inference has to be used. This makes the performance overhead when an 
exception occurs much larger and less predictable than it need be. This
problem i largely C++ specific. Second, the current C++ (and Ada) system 
encourages the use of exceptions for unhandleable problems; memory faults 
and programmer errors. This means both that users are using inappropriate 
methods for dealing with those problems when contract based programming 
would be better, and throwing an exception is more common than
it need be. If throwing an exception is not uncommon then the performance 
when throwing an exception is more of an issue. Partly as a result Ada 2012
added contract based programming methods. Third, because of a combination
of the second issue and C++’s automatic passing of exceptions up the stack,
it is harder for programmers and compilers to reason about exceptions.
This leads to more lost optimizations.

> On Sep 4, 2018, at 12:41 AM, Van Snyder via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
> On Mon, 2018-09-03 at 23:22 -0600, William Clodius via J3 wrote:
>> I thought about writing a paper on the semantics of exception handling, but decided against
>> it. However my research did find some references. To me the most useful for J3 would be Herb 
>> Sutter’s paper for SC22/WG21, "Zero-overhead deterministic exceptions: Throwing values”, 
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf an an alternative C++ 
>> exception handling scheme that he hopes would have much lower overhead than  the current C++ 
>> scheme. FWIW this paper has an extensive reference list that includes other papers/blogs that 
>> I also found interesting.
> 
> I learned a few years ago from Randy Brukardt that the exception system
> in the Janus Ada processor (the one he's responsible for) has, in his
> words "very low overhead" unless an exception occurs.
> 
> He also told me that the exception system in the GNU Ada Translator has
> no overhead unless an exception occurs.  Maybe it uses the method Sutter
> described.  But it's quite a bit older than 2018, so maybe Robert Dewar
> and his colleagues invented a different zero-overhead method.
> 
> There is no excuse to object to exception handling on performance
> grounds.
> 
> BTW, if a multilanguage program that appears to the Fortran parts of it
> to be C, are actually C++ or Ada, in our present condition, if they
> throw an exception, it would skip over any intermediate Fortran parts,
> and their finalizers wouldn't be run, and their allocatable and
> automatic variables wouldn't be cleaned up.  There is a chance that a
> Fortran exception system could be integrated with a companion
> processor's exception system.
> 
> 



More information about the J3 mailing list