Topic: Exception throwing that is not specified in the exception-specification.
Author: stkim@yujinrobot.com ("Kim, Seungtai")
Date: Thu, 10 Feb 2005 17:16:14 GMT Raw View
I throw an exception in a funtion which has an exception list.
And the thrown exception is not specified in the list, but the exception
list has the type of std::bad_exception.
In this cas, the Standard says that
15.5.2/2
... If the exception specification does not include the class
std::bad_exception (18.6.2.1) then the function terminate()
is called, otherwise the thrown exception is replaced by an
implementation defined object of the type std::bad_exception
and the search for another handler will continue at the call
of the function whose exception specification was violated.
So, I expect that bellow program should print
Bad Exception
But, any of the my tested environments dose not. They are
VC++6.0(+sp5,6), VC++.NET 2003, and g++ 2.96.
--Program
#include <iostream>
#include <exception>
class error_type1 {};
class error_type2 {};
void f ()
throw ( error_type2, std::bad_exception ) { throw error_type1(); }
int main( )
{
try
{
f();
}
catch ( error_type1)
{
std::cout << "Error Type 1" << std::endl;
}
catch ( error_type2)
{
std::cout << "Error Type 2 " << std::endl;
}
catch ( std::bad_exception )
{
std::cout << "Bad Exception" << std::endl;
}
}
Am I wrong and miss somthing or they all miss the issue?
--
S Kim <stkim@yujinrobot.com>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Date: Sat, 12 Feb 2005 19:13:03 GMT Raw View
"Kim, Seungtai" wrote:
> I throw an exception in a funtion which has an exception list.
> And the thrown exception is not specified in the list, but the exception
> list has the type of std::bad_exception.
<snip>
> So, I expect that bellow program should print
>
> Bad Exception
>
> But, any of the my tested environments dose not. They are
> VC++6.0(+sp5,6), VC++.NET 2003, and g++ 2.96.
<snip>
> Am I wrong and miss somthing or they all miss the issue?
None of those compilers support exception specifications, except that
VC++ 7.1 supports empty exception specifications. VC++ normally warns
where it's ignoring an exception specification.
--
Ben Hutchings
73.46% of all statistics are made up.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]