dieser Beispielcode Gegeben:C++ Ausnahmen und Vererbung von std :: exception
#include <iostream>
#include <stdexcept>
class my_exception_t : std::exception
{
public:
explicit my_exception_t()
{ }
virtual const char* what() const throw()
{ return "Hello, world!"; }
};
int main()
{
try
{ throw my_exception_t(); }
catch (const std::exception& error)
{ std::cerr << "Exception: " << error.what() << std::endl; }
catch (...)
{ std::cerr << "Exception: unknown" << std::endl; }
return 0;
}
ich folgende Ausgabe:
Exception: unknown
doch einfach das Erbe my_exception_t
von std::exception
public
machen, ich die folgende Ausgabe:
Exception: Hello, world!
Könnte jemand pl erklären Sie mir einfach, warum die Art der Erbschaft in diesem Fall wichtig ist? Bonuspunkte für eine Referenz im Standard.
Akzeptiert für die Standardreferenz; Vielen Dank! – fbrereto