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/slideio_base_def.hpp"
6#include <iostream>
7#include <sstream>
8#include <string.h>
9
10#if defined(_MSC_VER)
11#pragma warning( push )
12#pragma warning(disable: 4251 4275)
13#endif
14
15namespace slideio {
16 struct SLIDEIO_BASE_EXPORTS RuntimeError : public std::exception {
17 template <typename T>
18 RuntimeError& operator << (T rhs) {
19 m_innerStream << rhs;
20 return *this;
21 }
22 RuntimeError() = default;
23 RuntimeError(RuntimeError& rhs) {
24 std::string message = rhs.m_innerStream.str();
25 if(!m_shown) {
26 log(message);
27 }
28 m_innerStream << message;
29 }
30 virtual const char* what() const noexcept {
31 m_message = m_innerStream.str();
32 return m_message.c_str();
33 }
34 private:
35 void log(const std::string& message);
36 private:
37 std::stringstream m_innerStream;
38 mutable std::string m_message;
39 bool m_shown = false;
40 };
41}
42
43#define RAISE_RUNTIME_ERROR throw slideio::RuntimeError() << __FILE__ << ":" << __LINE__ << ":"
44
45#if defined(_MSC_VER)
46#pragma warning( pop )
47#endif
Definition: exceptions.hpp:15