Hard-abort on assertion and show detailed information, solves #2579

From

> [warn} oops

to

> [assert] /tmp/osrm-backend/src/extractor/extractor.cpp:79
> in: int osrm::extractor::Extractor::run(): false
> terminate called without an active exception
This commit is contained in:
Daniel J. Hofmann 2016-06-23 18:56:56 +02:00
parent 6dedd9cb72
commit df877aca1b
2 changed files with 7 additions and 26 deletions

View File

@ -1,20 +0,0 @@
#ifndef OSRM_ASSERT_HPP
#define OSRM_ASSERT_HPP
#include <boost/assert.hpp>
#include <stdexcept>
namespace osrm
{
namespace util
{
// Assertion type to be thrown for stack unwinding
struct assertionError final : std::logic_error
{
assertionError(const char *msg) : std::logic_error{msg} {}
};
}
}
#endif

View File

@ -1,16 +1,17 @@
#include "util/assert.hpp"
#include <boost/assert.hpp>
#include <sstream>
#include <exception>
#include <iostream>
namespace
{
// We throw to guarantee for stack-unwinding and therefore our destructors being called.
// We hard-abort on assertion violations.
void assertion_failed_msg_helper(
char const *expr, char const *msg, char const *function, char const *file, long line)
{
std::ostringstream fmt;
fmt << file << ":" << line << "\nin: " << function << ": " << expr << "\n" << msg;
throw osrm::util::assertionError{fmt.str().c_str()};
std::cerr << "[assert] " << file << ":" << line << "\nin: " << function << ": " << expr << "\n"
<< msg;
std::terminate();
}
}