CppEphem
CEException.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * CEException.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2019 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
27 #include "CEException.h"
28 
29 
30 /**********************************************************************/
34 CEExceptionHandler::CEExceptionHandler(const std::string& origin,
35  const std::string& message,
36  const std::string& type) :
38 {
39  origin_ = origin;
40  message_ += message;
41  type_ = type;
42 }
43 
44 
45 /**********************************************************************/
49 const char* CEExceptionHandler::what() const noexcept
50 {
51  // Define the header of the error message
52  full_msg_.clear();
53  full_msg_ += "[ERROR] " + type_ + ": " + origin_ + "\n" +
54  message_ + "\n" + backtrace_ + "\n";
55 
56  return full_msg_.c_str();
57 }
58 
59 
60 /**********************************************************************/
64 void CEExceptionHandler::message_append(const std::string& msg)
65 {
66  message_ += msg;
67 }
68 
69 
70 /**********************************************************************/
74 void CEExceptionHandler::message(const std::string& msg)
75 {
76  message_ = msg;
77 }
78 
79 
80 /**********************************************************************/
83 const char* CEExceptionHandler::message(void) const noexcept
84 {
85  return message_.c_str();
86 }
87 
88 
89 /**********************************************************************/
92 const char* CEExceptionHandler::trace(void) const noexcept
93 {
94  return backtrace_.c_str();
95 }
96 
97 
98 /**********************************************************************/
103 CEException::invalid_value::invalid_value(const std::string& origin,
104  const std::string& message) :
105  CEExceptionHandler(origin, message, "Invalid Value")
106 {}
107 
108 
109 /**********************************************************************/
114 CEException::invalid_delimiter::invalid_delimiter(const std::string& origin,
115  const std::string& message) :
116  CEExceptionHandler(origin, message, "Invalid Delimiter")
117 {}
118 
119 
120 /**********************************************************************/
126  const std::string& message) :
127  CEExceptionHandler(origin, message, "Corrections File Load Error")
128 {}
129 
130 
131 /**********************************************************************/
136 CEException::sofa_exception::sofa_exception(const std::string& origin,
137  const std::string& sofa_method,
138  const std::string& message) :
139  CEExceptionHandler(origin, message, "SOFA exception")
140 {
141  // Overwrite the message
142  this->message("SOFA method: " + sofa_method + "; " + message);
143 }
144 
145 
146 /**********************************************************************/
154 CEException::sofa_error::sofa_error(const std::string& origin,
155  const std::string& sofa_method,
156  const int& errcode,
157  const std::string& message) :
158  CEExceptionHandler(origin, message, "SOFA error")
159 {
160  // Overwrite the message
161  this->message("SOFA method: " + sofa_method + ", ErrCode: "+ std::to_string(errcode) +
162  "\n" + message);
163 }
CEExceptionHandler::CEExceptionHandler
CEExceptionHandler()
Definition: CEException.h:50
CEExceptionHandler
Definition: CEException.h:30
CEExceptionHandler::full_msg_
std::string full_msg_
Definition: CEException.h:78
CEException::corr_file_load_error::corr_file_load_error
corr_file_load_error(const std::string &origin, const std::string &message)
Generate an exception of type "corr_file_load_error".
Definition: CEException.cpp:124
CEExceptionHandler::trace
virtual const char * trace(void) const noexcept
Return the backtrace string.
Definition: CEException.cpp:91
CEException.h
CEException::sofa_exception::sofa_exception
sofa_exception(const std::string &origin, const std::string &sofa_method, const std::string &message)
Generate an exception of type "sofa_exception".
Definition: CEException.cpp:135
CEExceptionHandler::origin_
std::string origin_
Definition: CEException.h:74
CEExceptionHandler::message_append
virtual void message_append(const std::string &msg)
Append a string to the end of the message.
Definition: CEException.cpp:63
CEException::invalid_delimiter::invalid_delimiter
invalid_delimiter(const std::string &origin, const std::string &message)
Generate an exception of type "invalid_delimiter".
Definition: CEException.cpp:113
CEExceptionHandler::message
virtual const char * message(void) const noexcept
Return the message passed by the user.
Definition: CEException.cpp:82
CEException::invalid_value::invalid_value
invalid_value(const std::string &origin, const std::string &message)
Generate an exception of type "invalid_value".
Definition: CEException.cpp:102
CEExceptionHandler::what
virtual const char * what() const noexcept
Generates and returns the error message.
Definition: CEException.cpp:48
CEExceptionHandler::message_
std::string message_
Definition: CEException.h:76
CEExceptionHandler::backtrace_
std::string backtrace_
Definition: CEException.h:77
CEExceptionHandler::type_
std::string type_
Definition: CEException.h:75
CEException::sofa_error::sofa_error
sofa_error(const std::string &origin, const std::string &sofa_method, const int &errcode, const std::string &message)
Generate an exception of type "sofa_error".
Definition: CEException.cpp:153