C++相談室 part89
■ このスレッドは過去ログ倉庫に格納されています
0077デフォルトの名無しさん
2011/05/10(火) 06:23:41.02#include <stdexcept>
#include <iostream>
class foo_exception : public std::runtime_error {
public: explicit foo_exception( const std::string& what_arg ) : std::runtime_error( what_arg ) {};
};
void f1( void ) { throw std::runtime_error( "ehh" ); }
void f2( void ) { throw foo_exception( "gee" ); }
void check( void (*f)(void) ) {
try {
f();
} catch( foo_exception& e ) {
std::cout << "foo_exception" << std::endl;
std::cout << e.what() << std::endl;
} catch( std::runtime_error& e ) {
std::cout << "std::runtime_error" << std::endl;
std::cout << e.what() << std::endl;
}
}
int main( void )
{
check(f1);
check(f2);
return 0;
}
Output:
std::runtime_error
ehh
foo_exception
gee
■ このスレッドは過去ログ倉庫に格納されています