Questions of C++ exceptions

W

Wat

1. Is this correct in C++?

int foo() throw(); // can not throw any exception

int foo(); // can throw any exception

2. Exception specification:

int foo() throw(type list);

For example, void foo() throw(int, over_flow);

Should two catch blocks built to catch "int" and "over_flow" separately? Or
just one block of catch, which catches both "int" and "over_flow"?

3. If "int foo() throw();" does mean "can not throw any exception", then
what happens if an exception do occur inside foo()?

4. Does the above exception specification also apply to memeber functions of
classes?

Thanks for your help!
 
V

Victor Bazarov

Wat said:
1. Is this correct in C++?

int foo() throw(); // can not throw any exception
Yes.

int foo(); // can throw any exception
Yes.

2. Exception specification:

int foo() throw(type list);

For example, void foo() throw(int, over_flow);

Should two catch blocks built to catch "int" and "over_flow" separately?
Or
just one block of catch, which catches both "int" and "over_flow"?

There is no way in one catch block to catch two different types, unless
they are related classes and _the_base_one_ is caught by a reference or
a pointer.
3. If "int foo() throw();" does mean "can not throw any exception", then
what happens if an exception do occur inside foo()?

'unexpected()' is called.
4. Does the above exception specification also apply to memeber functions
of
classes?

Of course.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top