mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 12:28:13 -04:00
feat(error): add DWARFS_PANIC
This commit is contained in:
parent
6361d8d814
commit
e8e2323eea
@ -74,16 +74,22 @@ class system_error : public std::system_error {
|
||||
#define DWARFS_CHECK(expr, message) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
assertion_failed(#expr, message, std::source_location::current()); \
|
||||
::dwarfs::assertion_failed(#expr, message, \
|
||||
std::source_location::current()); \
|
||||
} \
|
||||
} while (0)
|
||||
} while (false)
|
||||
|
||||
#define DWARFS_PANIC(message) \
|
||||
do { \
|
||||
::dwarfs::handle_panic(message, std::source_location::current()); \
|
||||
} while (false)
|
||||
|
||||
#define DWARFS_NOTHROW(expr) \
|
||||
[&]() -> decltype(expr) { \
|
||||
try { \
|
||||
return expr; \
|
||||
} catch (...) { \
|
||||
handle_nothrow(#expr, std::source_location::current()); \
|
||||
::dwarfs::handle_nothrow(#expr, std::source_location::current()); \
|
||||
} \
|
||||
}()
|
||||
|
||||
@ -96,4 +102,7 @@ handle_nothrow(std::string_view expr, std::source_location loc);
|
||||
assertion_failed(std::string_view expr, std::string_view message,
|
||||
std::source_location loc);
|
||||
|
||||
[[noreturn]] void
|
||||
handle_panic(std::string_view message, std::source_location loc);
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -93,4 +93,10 @@ void assertion_failed(std::string_view expr, std::string_view msg,
|
||||
do_terminate();
|
||||
}
|
||||
|
||||
void handle_panic(std::string_view msg, std::source_location loc) {
|
||||
std::cerr << "Panic: " << msg << " in " << loc.file_name() << "("
|
||||
<< loc.line() << ")\n";
|
||||
do_terminate();
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
|
Loading…
x
Reference in New Issue
Block a user