libHiRISE
|
00001 /* HiRISE Exceptions 00002 00003 PIRL CVS ID: Exceptions.hh,v 2.4 2020/02/14 00:58:12 schaller Exp 00004 00005 Copyright (C) 2003-2020 Arizona Board of Regents on behalf of the Lunar and 00006 Planetary Laboratory at the University of Arizona. 00007 00008 Licensed under the Apache License, Version 2.0 (the "License"); you may not use 00009 this file except in compliance with the License. You may obtain a copy of the 00010 License at 00011 00012 http://www.apache.org/licenses/LICENSE-2.0 00013 00014 Unless required by applicable law or agreed to in writing, software distributed 00015 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 00016 CONDITIONS OF ANY KIND, either express or implied. See the License for the 00017 specific language governing permissions and limitations under the License. 00018 00019 */ 00020 00021 #ifndef _UA_HIRISE_EXCEPTIONS_HEADER_ 00022 #define _UA_HIRISE_EXCEPTIONS_HEADER_ 00023 00024 #include <exception> 00025 #include <stdexcept> 00026 #include <string> 00027 00028 namespace UA 00029 { 00030 00031 namespace HiRISE 00032 { 00033 00034 /*=***************************************************************************** 00035 Exception Class 00036 *******************************************************************************/ 00037 00063 class Exception 00064 : public std::exception 00065 { 00066 00067 public: 00068 00069 /*============================================================================== 00070 Constants 00071 */ 00073 static const char* const 00074 ID; 00075 00076 /*============================================================================== 00077 Constructors 00078 */ 00079 00090 explicit Exception 00091 ( 00092 const std::string& message = "", 00093 const char* caller_id = NULL 00094 ); 00095 00096 // Destructor 00097 virtual ~Exception () throw () {} 00098 00099 /*============================================================================== 00100 Accessors 00101 */ 00102 00109 const char* what () const throw (); 00110 00116 std::string message () const throw (); 00117 00127 void message (const std::string& new_message); 00128 00129 private: 00130 00131 /*============================================================================== 00132 Private Data 00133 */ 00134 00135 std::string 00136 Message; 00137 std::string::size_type 00138 User_Message_Index; 00139 00140 }; // Exception class 00141 00142 /*=***************************************************************************** 00143 Error Struct (Class) 00144 *******************************************************************************/ 00145 00150 struct Error 00151 : public Exception 00152 { 00159 explicit Error 00160 ( 00161 const std::string& message = "", 00162 const char *caller_id = NULL 00163 ) 00164 : Exception (std::string ("Error: ") + message, caller_id) 00165 {} 00166 00167 }; // Error struct 00168 00169 /*=***************************************************************************** 00170 Invalid_Argument Struct (Class) 00171 *******************************************************************************/ 00172 00177 struct Invalid_Argument 00178 : public Error, 00179 public std::invalid_argument 00180 { 00187 explicit Invalid_Argument 00188 ( 00189 const std::string& message = "", 00190 const char *caller_id = NULL 00191 ) 00192 : Error (std::string ("Invalid_Argument\n") + message, caller_id), 00193 std::invalid_argument 00194 ( 00195 std::string (Exception::ID) 00196 + (caller_id ? (std::string ("\n") + caller_id) : "") 00197 ) 00198 {} 00199 00200 }; // Invalid_Argument struct 00201 00202 /*=***************************************************************************** 00203 Out_of_Range Struct (Class) 00204 *******************************************************************************/ 00205 00210 struct Out_of_Range : 00211 public Error, 00212 public std::out_of_range 00213 { 00220 explicit Out_of_Range 00221 ( 00222 const std::string& message = "", 00223 const char *caller_id = NULL 00224 ) 00225 : Error (std::string ("Out_of_Range\n") + message, caller_id), 00226 std::out_of_range 00227 ( 00228 std::string (Exception::ID) 00229 + (caller_id ? (std::string ("\n") + caller_id) : "") 00230 ) 00231 {} 00232 00233 }; // Out_of_Range struct 00234 00235 } // HiRISE namespace 00236 00237 } // UA namespace 00238 00239 #endif