TITLE: hidden cost of using exception specifications (Newsgroup: comp.lang.c++.moderated, 13 Jan 99) COLLINS: Ian Collins < > Exception specifications are a great aid to code maintenance, but has > anyone found a compiler that generates faster code when they are used? > > I Have tried test code with gcc2.8.1 and Sun CC4.2 and 5, in all cases > the specification resulted in a slightly slower runtime. CLAMAGE: Steve Clamage, stephen.clamage@sun.com Maybe you weren't testing for the right thing. If you write int f() // no exception spec { ... } the compiler does not need add any code to f verify exceptions. If you write int g() throw() { return f(); } the compiler in general needs to add code to g to ensure no exceptions escape from it. But if f were declared to not to throw any exceptions, the compiler can see that g cannot throw an exception, and so can eliminate the checks on g. The Sun compilers in fact do that. Adding exeception specifications to a function can increase the amount of code involved for that function. It might, however, decrease the amount of code involved for other functions that call it.