Skip to content
Snippets Groups Projects
Commit 5852f11f authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Improve exception treatment

parent f281e31d
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <output/VTKWriter.hpp>
#include <utils/Exceptions.hpp>
#include <utils/SignalManager.hpp>
#include <utils/Timer.hpp>
#include <algebra/TinyMatrix.hpp>
......@@ -410,12 +411,17 @@ main(int argc, char* argv[])
<< "] Execution time: " << rang::style::bold << method_cost.second << rang::style::reset << '\n';
}
}
catch (const NormalError& e) {
catch (const IExitError& e) {
if (SignalManager::pauseOnError()) {
std::rethrow_exception(std::current_exception());
} else {
// Each failing process must write
std::cerr.setstate(std::ios::goodbit);
std::cerr << e.what() << '\n';
return 1;
}
}
return 0;
}
......@@ -3,27 +3,30 @@
#include <rang.hpp>
#include <sstream>
#include <string>
RawError::RawError(std::string_view error_msg) : IExitError(std::string{error_msg}) {}
NormalError::NormalError(std::string_view error_msg)
: std::runtime_error([&] {
: IExitError([&] {
std::ostringstream os;
os << rang::style::bold << "Error:" << rang::style::reset << '\n' << error_msg << '\n';
os << rang::style::bold << "Error:" << rang::style::reset << ' ' << error_msg;
return os.str();
}())
{}
UnexpectedError::UnexpectedError(std::string_view error_msg)
: std::runtime_error([&] {
: IBacktraceError([&] {
std::ostringstream os;
os << rang::fgB::red << "Unexpected error:" << rang::style::reset << '\n' << error_msg << '\n';
os << rang::fgB::red << "Unexpected error:" << rang::style::reset << ' ' << error_msg;
return os.str();
}())
{}
NotImplementedError::NotImplementedError(std::string_view error_msg)
: std::runtime_error([&] {
: IBacktraceError([&] {
std::ostringstream os;
os << rang::fgB::yellow << "Not implemented yet:" << rang::style::reset << '\n' << error_msg << '\n';
os << rang::fgB::yellow << "Not implemented yet:" << rang::style::reset << ' ' << error_msg;
return os.str();
}())
{}
......@@ -3,17 +3,34 @@
#include <stdexcept>
struct NormalError : public std::runtime_error
struct IExitError : public std::runtime_error
{
IExitError(std::string_view error_msg) : std::runtime_error(std::string{error_msg}){};
virtual ~IExitError() = default;
};
struct RawError : public IExitError
{
RawError(std::string_view error_msg);
};
struct NormalError : public IExitError
{
NormalError(std::string_view error_msg);
};
struct UnexpectedError : public std::runtime_error
struct IBacktraceError : public std::runtime_error
{
IBacktraceError(const std::string& error_msg) : std::runtime_error(std::string{error_msg}){};
virtual ~IBacktraceError() = default;
};
struct UnexpectedError : IBacktraceError
{
UnexpectedError(std::string_view error_msg);
};
struct NotImplementedError : public std::runtime_error
struct NotImplementedError : IBacktraceError
{
NotImplementedError(std::string_view error_msg);
};
......
......@@ -15,6 +15,12 @@
bool SignalManager::s_pause_on_error = false;
bool
SignalManager::pauseOnError()
{
return s_pause_on_error;
}
void
SignalManager::setPauseForDebug(const bool& pause_on_error)
{
......
......@@ -12,6 +12,7 @@ struct SignalManager
static void handler(int signal);
public:
static bool pauseOnError();
static void setPauseForDebug(const bool& pause_on_error);
static void init(const bool& enable);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment