Skip to content
Snippets Groups Projects
Commit 0ced7265 authored by Florian Fischer's avatar Florian Fischer
Browse files

write death message to std:err and support stream formatting in DIE_MSG*

The stream formatting for DIE_MSG is already wrongly used in
IoContext, EchoClient and LawsDispatcher.
parent fef50ae8
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ void die(const char* message, bool usePerror) {
if (usePerror) {
std::perror(message);
} else {
std::cout << message << std::endl;
std::cerr << message << std::endl;
}
exit(EXIT_FAILURE);
}
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2021 Florian Schmaus, Florian Fischer
#pragma once
#include <functional>
......@@ -9,8 +9,16 @@ using func_t = std::function<void()>;
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define DIE die(__FILE__ ":" TOSTRING(__LINE__), false)
#define DIE_MSG(x) die(__FILE__ ":" TOSTRING(__LINE__) " " #x, false)
#define DIE_MSG_ERRNO(x) die(__FILE__ ":" TOSTRING(__LINE__) " " #x, true)
// See Debug.hpp why we disable clang-format for the multi statement macro definitions
// clang-format off
// NOLINTNEXTLINE(bugprone-macro-parentheses)
#define DIE_MSG(x) do { std::stringstream sst; sst << __FILE__ ":" TOSTRING(__LINE__) " " << x; die(sst.str().c_str(), false); } while (false)
// NOLINTNEXTLINE(bugprone-macro-parentheses)
#define DIE_MSG_ERRNO(x) do { std::stringstream sst; sst << __FILE__ ":" TOSTRING(__LINE__) " " << x; die(sst.str().c_str(), true); } while (false)
// clang-format on
// We compile with -fno-exceptions for the moment.
//#define THROW(x) do { throw std::runtime_error(x); } while (false)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment