Home Messages Index
[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index

Re: throw exception();

  • Subject: Re: throw exception();
  • From: Sebastian Redl <e0226430@student.tuwien.ac.at>
  • Date: Mon, 17 Jan 2005 09:11:06 +0100
  • Newsgroups: comp.lang.c++
  • Organization: TU Wien
  • References: <10umh424f0gad9b@news.supernews.com> <csfl1u$1dub$1@godfrey.mcc.ac.uk>
  • User-agent: KNode/0.7.1
  • Xref: news.mcc.ac.uk comp.lang.c++:694323
Roy Schestowitz wrote:

> 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.

-- 
Sebastian Redl

[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index