src: add assert_noexcept()

This commit is contained in:
Markus F.X.J. Oberhumer
2023-07-08 12:06:27 +02:00
parent 1d71dd3851
commit 682a1e97e4
12 changed files with 248 additions and 167 deletions
+17 -1
View File
@@ -72,7 +72,9 @@ Throwable::~Throwable() noexcept {
void throwCantPack(const char *msg) {
// UGLY, but makes things easier
if (opt->cmd == CMD_COMPRESS)
if (opt->cmd == CMD_NONE)
throw CantPackException(msg);
else if (opt->cmd == CMD_COMPRESS)
throw CantPackException(msg);
else if (opt->cmd == CMD_FILEINFO)
throw CantPackException(msg);
@@ -167,6 +169,20 @@ void throwCantUnpack(const char *format, ...) {
//
**************************************************************************/
void assertFailed(const char *expr, const char *file, int line, const char *func) noexcept {
fflush(stdout);
fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
std::terminate();
}
void throwAssertFailed(const char *expr, const char *file, int line, const char *func) {
if (opt->debug.debug_level >= 1) {
throwCantPack("corrupted file; details: %s (%s: %s: %d)", expr, file, func, line);
} else {
throwCantPack("corrupted file; try '--debug' for more details");
}
}
const char *prettyName(const char *n) noexcept {
if (n == nullptr)
return "(null)";