nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef EXCEPTION_H 00024 #define EXCEPTION_H 00025 00026 #include <string> 00027 00028 namespace nux 00029 { 00030 00031 // ***************** 00032 // * * 00033 // * Exception * 00034 // * * 00035 // ***************** 00036 // 00037 // The exception handling classes from the STL do what we want, 00038 // so this is nothing more than a base class for any of our 00039 // derived exceptions. I have changed the constructor to take a 00040 // std::string object, but this gets converted before calling 00041 // std::exception. 00042 00043 00044 class Exception : public std::exception 00045 { 00046 public: 00047 Exception (std::string name) throw() 00048 : std::exception (), name_ (name) 00049 { 00050 } 00051 00052 virtual ~Exception () throw () {} 00053 00054 virtual const char *what () const throw() 00055 { 00056 return name_.c_str(); 00057 } 00058 00059 protected: 00060 std::string name_; 00061 }; 00062 00063 00064 // ************************ 00065 // * * 00066 // * Derived Exceptions * 00067 // * * 00068 // ************************ 00069 00070 class BoundsException : public Exception 00071 { 00072 public: 00073 BoundsException (std::string name = "") 00074 : Exception ("apBoundsException: " + name) 00075 { 00076 } 00077 }; 00078 00079 class NotSupportedException : public Exception 00080 { 00081 public: 00082 NotSupportedException (std::string name = "") 00083 : Exception ("NotSupportedException: " + name) 00084 { 00085 } 00086 }; 00087 00088 class DivisionByZeroException : public Exception 00089 { 00090 public: 00091 DivisionByZeroException (std::string name = "") 00092 : Exception ("DivisionByZeroException: " + name) 00093 { 00094 } 00095 }; 00096 00097 class InvalidIndexException : public Exception 00098 { 00099 public: 00100 InvalidIndexException (std::string name = "") 00101 : Exception ("InvalidIndexException: " + name) 00102 { 00103 } 00104 }; 00105 00106 } 00107 00108 #endif // EXCEPTION_H