Spaces:
Runtime error
Runtime error
File size: 687 Bytes
8df6da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include "exception.hh"
#include <cstdio>
#include <cstring>
errno_exception::errno_exception(int errno)
: _errno(errno)
{
}
int errno_exception::errno() const
{
return _errno;
}
const char *errno_exception::what()
{
std::snprintf(_buf, sizeof _buf, "error: %s (%d)",
std::strerror(_errno), _errno);
return _buf;
}
int try_main(int (*main)(int argc, char** argv), int argc, char** argv,
int ret_on_exception)
{
try {
return main(argc, argv);
} catch (std::exception& e) {
std::fprintf(stderr, "exception: %s\n", e.what());
} catch (...) {
std::fprintf(stderr, "unknown exception\n");
}
return ret_on_exception;
}
|