1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
//$$ newmatex.cpp Exception handler
// Copyright (C) 1992,3,4,7: R B Davies
#define WANT_STREAM // include.h will get stream fns
#include "include.h" // include standard files
#include "config.h"
#include "newmat.h"
#ifdef use_namespace
namespace NEWMAT {
#endif
unsigned long OverflowException::Select;
unsigned long SingularException::Select;
unsigned long NPDException::Select;
unsigned long ConvergenceException::Select;
unsigned long ProgramException::Select;
unsigned long IndexException::Select;
unsigned long VectorException::Select;
unsigned long NotSquareException::Select;
unsigned long SubMatrixDimensionException::Select;
unsigned long IncompatibleDimensionsException::Select;
unsigned long NotDefinedException::Select;
unsigned long CannotBuildException::Select;
unsigned long InternalException::Select;
static void MatrixDetails(const GeneralMatrix& A)
// write matrix details to Exception buffer
{
MatrixBandWidth bw = A.BandWidth(); int ubw = bw.upper; int lbw = bw.lower;
BaseException::AddMessage("MatrixType = ");
BaseException::AddMessage(A.Type().Value());
BaseException::AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows());
BaseException::AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols());
if (lbw >=0)
{ BaseException::AddMessage("; lower BW = "); BaseException::AddInt(lbw); }
if (ubw >=0)
{ BaseException::AddMessage("; upper BW = "); BaseException::AddInt(ubw); }
BaseException::AddMessage("\n");
}
NPDException::NPDException(const GeneralMatrix& A)
: Runtime_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: matrix not positive definite\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
SingularException::SingularException(const GeneralMatrix& A)
: Runtime_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: matrix is singular\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
ConvergenceException::ConvergenceException(const GeneralMatrix& A)
: Runtime_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: process fails to converge\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
ConvergenceException::ConvergenceException(const char* c) : Runtime_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(c); AddMessage("\n\n");
if (c) Tracer::AddTrace();
}
OverflowException::OverflowException(const char* c) : Runtime_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(c); AddMessage("\n\n");
if (c) Tracer::AddTrace();
}
ProgramException::ProgramException(const char* c) : Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(c); AddMessage("\n\n");
if (c) Tracer::AddTrace();
}
ProgramException::ProgramException(const char* c, const GeneralMatrix& A)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(c); AddMessage("\n\n");
MatrixDetails(A);
if (c) Tracer::AddTrace();
}
ProgramException::ProgramException(const char* c, const GeneralMatrix& A,
const GeneralMatrix& B) : Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(c); AddMessage("\n\n");
MatrixDetails(A); MatrixDetails(B);
if (c) Tracer::AddTrace();
}
ProgramException::ProgramException(const char* c, MatrixType a, MatrixType b)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(c); AddMessage("\nMatrixTypes = ");
AddMessage(a.Value()); AddMessage("; ");
AddMessage(b.Value()); AddMessage("\n\n");
if (c) Tracer::AddTrace();
}
VectorException::VectorException() : Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
Tracer::AddTrace();
}
VectorException::VectorException(const GeneralMatrix& A)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
NotSquareException::NotSquareException(const GeneralMatrix& A)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: matrix is not square\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
SubMatrixDimensionException::SubMatrixDimensionException()
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: incompatible submatrix dimension\n\n");
Tracer::AddTrace();
}
IncompatibleDimensionsException::IncompatibleDimensionsException()
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: incompatible dimensions\n\n");
Tracer::AddTrace();
}
IncompatibleDimensionsException::IncompatibleDimensionsException
(const GeneralMatrix& A, const GeneralMatrix& B)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: incompatible dimensions\n\n");
MatrixDetails(A); MatrixDetails(B);
Tracer::AddTrace();
}
NotDefinedException::NotDefinedException(const char* op, const char* matrix)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: ");
AddMessage(op);
AddMessage(" not defined for ");
AddMessage(matrix);
AddMessage("\n\n");
Tracer::AddTrace();
}
CannotBuildException::CannotBuildException(const char* matrix)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: cannot build matrix type ");
AddMessage(matrix); AddMessage("\n\n");
Tracer::AddTrace();
}
IndexException::IndexException(int i, const GeneralMatrix& A)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: index error: requested index = ");
AddInt(i); AddMessage("\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
IndexException::IndexException(int i, int j, const GeneralMatrix& A)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: index error: requested indices = ");
AddInt(i); AddMessage(", "); AddInt(j);
AddMessage("\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
IndexException::IndexException(int i, const GeneralMatrix& A, bool)
: Logic_error()
{
Select = BaseException::Select;
AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
AddInt(i);
AddMessage("\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
: Logic_error()
{
Select = BaseException::Select;
AddMessage(
"detected by Newmat: element error: requested indices (wrt 0) = ");
AddInt(i); AddMessage(", "); AddInt(j);
AddMessage("\n\n");
MatrixDetails(A);
Tracer::AddTrace();
}
InternalException::InternalException(const char* c) : Logic_error()
{
Select = BaseException::Select;
AddMessage("internal error detected by Newmat: please inform author\n");
AddMessage(c); AddMessage("\n\n");
Tracer::AddTrace();
}
/************************* ExeCounter functions *****************************/
#ifdef DO_REPORT
int ExeCounter::nreports; // will be set to zero
ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
ExeCounter::~ExeCounter()
{
nreports++;
cout << "REPORT " << setw(6) << nreports << " "
<< setw(6) << fileid << " " << setw(6) << line
<< " " << setw(6) << nexe << "\n";
}
#endif
/**************************** error handler *******************************/
void MatrixErrorNoSpace(void* v) { if (!v) Throw(Bad_alloc()); }
// throw exception if v is null
/************************* miscellanous errors ***************************/
void CroutMatrix::GetRow(MatrixRowCol&)
{ Throw(NotDefinedException("GetRow","Crout")); }
void CroutMatrix::GetCol(MatrixRowCol&)
{ Throw(NotDefinedException("GetCol","Crout")); }
void CroutMatrix::operator=(const BaseMatrix&)
{ Throw(NotDefinedException("=","Crout")); }
void BandLUMatrix::GetRow(MatrixRowCol&)
{ Throw(NotDefinedException("GetRow","BandLUMatrix")); }
void BandLUMatrix::GetCol(MatrixRowCol&)
{ Throw(NotDefinedException("GetCol","BandLUMatrix")); }
void BandLUMatrix::operator=(const BaseMatrix&)
{ Throw(NotDefinedException("=","BandLUMatrix")); }
void BaseMatrix::IEQND() const
{ Throw(NotDefinedException("inequalities", "matrices")); }
#ifdef TEMPS_DESTROYED_QUICKLY_R
ReturnMatrixX::ReturnMatrixX(const ReturnMatrixX& tm)
: gm(tm.gm) { Throw(ProgramException("ReturnMatrixX error")); }
#endif
#ifdef use_namespace
}
#endif
|