00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef SCPPNT_NO_DIR_PREFIX
00018 #include "scppnt_error.h"
00019 #else
00020 #include "scppnt/scppnt_error.h"
00021 #endif
00022
00023 #include <cstring>
00024 #ifdef BOOST_NO_STDC_NAMESPACE
00025 namespace std
00026 { using ::strlen; using ::strncat;}
00027 #endif
00028
00029 namespace SCPPNT
00030 {
00031 Exception::Exception()
00032 {
00033 message[0] = 0;
00034 }
00035
00036 Exception::~Exception()
00037 {
00038 }
00039
00040
00041
00042
00043
00044 void Exception::AppendToMessage(const char *s)
00045 {
00046 if (s == 0)
00047 return;
00048
00049 int len = std::strlen(s);
00050 int currlen = std::strlen(message);
00051 int freechar = MaxChar() - currlen;
00052
00053 if (freechar <= 0 || len == 0)
00054 return;
00055
00056 if (len > freechar)
00057 len = freechar;
00058
00059 std::strncat(message, s, len);
00060
00061 message[len+currlen] = 0;
00062 }
00063
00064 LogicError::LogicError(const char *type, const char *mess, const char *func)
00065 {
00066
00067
00068
00069 AppendToMessage(type);
00070
00071 if (mess)
00072 {
00073 AppendToMessage(mess);
00074 AppendToMessage("\n");
00075 }
00076
00077 if (func)
00078 {
00079 AppendToMessage("in function ");
00080 AppendToMessage(func);
00081 AppendToMessage("\n");
00082 }
00083 }
00084
00085 LogicError::~LogicError()
00086 {
00087 }
00088
00089 InvalidArgument::InvalidArgument(const char *mess, const char *func) :
00090 LogicError("Invalid argument: ", mess, func)
00091 {
00092 }
00093
00094 RuntimeError::RuntimeError(const char *mess, const char *func)
00095 {
00096
00097
00098 if (mess)
00099 {
00100 AppendToMessage(mess);
00101 AppendToMessage("\n");
00102 }
00103
00104 if (func)
00105 {
00106 AppendToMessage("in function ");
00107 AppendToMessage(func);
00108 AppendToMessage("\n");
00109 }
00110 }
00111
00112 RuntimeError::~RuntimeError()
00113 {
00114 }
00115
00116 BoundsError::BoundsError(const char *func) :
00117 RuntimeError("Attempted to access element outside valid bounds", func)
00118 {
00119 }
00120
00121 BadDimension::BadDimension(const char *func) :
00122 RuntimeError("Argument has invalid dimension", func)
00123 {
00124 }
00125
00126 }