SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
exceptions.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5#include "slideio/base/log.hpp"
6
7#include <iostream>
8#include <sstream>
9#include <string.h>
10
11
12namespace slideio {
13 struct RuntimeError : public std::exception {
14 template <typename T>
15 RuntimeError& operator << (T rhs) {
16 m_innerStream << rhs;
17 return *this;
18 }
19 RuntimeError() = default;
20 RuntimeError(RuntimeError& rhs) {
21 std::string message = rhs.m_innerStream.str();
22 if(!m_shown) {
23 SLIDEIO_LOG(ERROR) << message;
24 }
25 m_innerStream << message;
26 }
27 virtual const char* what() const noexcept {
28 m_message = m_innerStream.str();
29 return m_message.c_str();
30 }
31 private:
32 std::stringstream m_innerStream;
33 mutable std::string m_message;
34 bool m_shown = false;
35 };
36}
37
38#define RAISE_RUNTIME_ERROR throw slideio::RuntimeError() << __FILE__ << ":" << __LINE__ << ":"
Definition: exceptions.hpp:12