throw exception();

D

Dave

Josuttis states that I may not throw an exception of type exception or of
one of the standard exception types used for language support. Where in the
Standard am I forbidden from "throw exception();"?

Thanks,
Dave
 
S

Sebastian Redl

Roy said:
Dave wrote:

I think the following will explain to you about all the exception types.

http://www.cplusplus.com/doc/tutorial/tut5-3.html

There are some things in this document I'd like to point out.
First, not really relevant to the topic at hand, that it uses <iostream.h>,
when it really should use <iostream>.

Second, and more importantly, it's got the wrong reason listed for when a
bad_exception is thrown. The document claims it's when "an exception
doesn't match any catch". This is wrong. The exception is thrown when an
exception doesn't match an explicit throws clause:
void foo() throws (std::runtime_error)
{
throw std::length_error();
}

I'm not sure why Josuttis would state that you MAY NOT throw a plain
std::exception - as far as I'm aware, nothing in the standard says so. But
you SHOULD NOT throw a plain std::exception, simply because it holds no
further information to the cause of the error. Always be as specific as is
reasonable.
 

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

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,642
Latest member
arunkumar99

Latest Threads

Top