Keyple Util C++ Library 2.0.0
Reference Terminal Reader API for C++
Exception.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#pragma once
14
15#include <exception>
16#include <memory>
17#include <stdexcept>
18#include <iostream>
19
20namespace keyple {
21namespace core {
22namespace util {
23namespace cpp {
24namespace exception {
25
26class Exception : public std::exception {
27public:
32
36 Exception(const Exception& o) : mMessage(o.mMessage), mCause(o.mCause) {}
37
41 Exception(const std::string& message) : mMessage(message), mCause(nullptr) {}
42
46 Exception(const std::string& message, const std::shared_ptr<Exception> cause)
47 : mMessage(message), mCause(cause) {}
48
52 const std::string& getMessage() const
53 {
54 return mMessage;
55 }
56
60 const std::shared_ptr<Exception> getCause() const
61 {
62 return mCause;
63 }
64
68 friend std::ostream& operator<<(std::ostream& os, const Exception& e)
69 {
70 os << "EXCEPTION: {"
71 << "MESSAGE = " << e.mMessage;
72
73 if (e.mCause != nullptr) {
74 os << ", CAUSE = " << e.mCause->what();
75 }
76
77 os << "}";
78
79 return os;
80 }
81
85 bool operator==(const Exception& o) const
86 {
87 return mMessage == o.mMessage &&
88 mCause== o.mCause;
89 }
90
91private:
95 const std::string mMessage;
96
100 const std::shared_ptr<Exception> mCause;
101};
102
103}
104}
105}
106}
107}
const std::shared_ptr< Exception > getCause() const
Definition: Exception.h:60
friend std::ostream & operator<<(std::ostream &os, const Exception &e)
Definition: Exception.h:68
Exception(const std::string &message)
Definition: Exception.h:41
bool operator==(const Exception &o) const
Definition: Exception.h:85
Exception(const std::string &message, const std::shared_ptr< Exception > cause)
Definition: Exception.h:46
const std::string & getMessage() const
Definition: Exception.h:52