dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Advanced
Nov 10, 1998

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Exception Specifications are Checked at Run Time

A function can specify explicitly what type of exception it may throw. An exception specification, however, is not checked at compile time, but rather at run time:
 
class X {};
int f();        // no exception specification, can throw any type of exception
void g(int j) throw(); // promises not to throw any exception at all
{	
  int result = f(); // if f throws an exception, g will violate its  guarantee not to throw an exception
                               //still, this is a perfectly legal code
}
There are several reasons for this runtime checking policy. In the example, f could be a legacy C function. It is impossible to force a C function to have an exception specification. Also, forcing the programmer to write unnecessary try/catch blocks in g (although f doesn't throw any exception at all) is an unacceptable burden. For these reasons, an exception specification is checked at run time.
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date