From a7db528ff34e5877f7fefe344a43090dcc013274 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 9 Mar 1998 18:13:46 +0000 Subject: [PATCH] Exception handling update git-svn-id: https://svn.dealii.org/trunk@49 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/dfmatrix.h | 50 ++++++++++++++++++++-- deal.II/lac/include/lac/dsmatrix.h | 23 +++++++++++ deal.II/lac/include/lac/dvector.h | 25 ++++++++++- deal.II/lac/include/lac/ivector.h | 23 ++++++++++- deal.II/lac/source/dfmatrix.cc | 21 ---------- deal.II/lac/source/dsmatrix.cc | 13 +++--- deal.II/lac/source/dvector.cc | 66 ++++++++++++++++-------------- deal.II/lac/source/ivector.cc | 18 ++++---- 8 files changed, 163 insertions(+), 76 deletions(-) diff --git a/deal.II/lac/include/lac/dfmatrix.h b/deal.II/lac/include/lac/dfmatrix.h index 861083594f..83b5f9ee09 100644 --- a/deal.II/lac/include/lac/dfmatrix.h +++ b/deal.II/lac/include/lac/dfmatrix.h @@ -13,6 +13,10 @@ #include #endif +#include + + + /** * Double precision full Matrix. * Memory for Components is supplied explicitly

@@ -154,8 +158,8 @@ class dFMatrix */ double operator() (int i, int j) const { - //THROW2((i<0) || (i>=dim_image), IntError(IntError::Range,i)); - //THROW2((j<0) || (j>=dim_range), IntError(IntError::Range,i)); + Assert ((i>=0) && (i=0) && (j=dim_image), IntError(IntError::Range,i)); - //THROW2((j<0) || (j>=dim_range), IntError(IntError::Range,i)); + Assert ((i>=0) && (i=0) && (j #endif +#include + + class ostream; template class DoFHandler; @@ -79,8 +82,28 @@ public: friend class ConstraintMatrix; friend class DoFHandler<1>; friend class DoFHandler<2>; + + /** + * Exception + */ + DeclException1 (ExcInvalidNumber, + int, + << "The provided number is invalid here: " << arg1); + /** + * Exception + */ + DeclException2 (ExcInvalidIndex, + int, int, + << "The given index " << arg1 + << " should be less than " << arg2 << "."); + }; + + + + + /* CLASS dSMatrix diff --git a/deal.II/lac/include/lac/dvector.h b/deal.II/lac/include/lac/dvector.h index f1d1f36b98..91456b8b09 100644 --- a/deal.II/lac/include/lac/dvector.h +++ b/deal.II/lac/include/lac/dvector.h @@ -18,6 +18,9 @@ #include #endif +#include + + /** * Double precision Vector. @@ -251,6 +254,24 @@ class dVector : public VectorBase */ void print(const char* format = 0) const; //@} + + /** + * Exception + */ + DeclException2 (ExcInvalidIndex, + int, int, + << "The given index " << arg1 + << " should be less than " << arg2 << "."); + /** + * Exception + */ + DeclException1 (ExcInvalidNumber, + int, + << "The provided number is invalid here: " << arg1); + /** + * Exception + */ + DeclException0 (ExcOutOfMemory); }; @@ -264,13 +285,13 @@ inline int dVector::n() const inline double dVector::operator() (int i) const { - //THROW2( (i<0) || (i>=dim), IntError(IntError::Range,i)); + Assert ((i>=0) || (i=dim), IntError(IntError::Range,i)); + Assert ((i>=0) || (i #endif +#include /** @@ -133,6 +134,24 @@ protected: */ void equ(int a, const iVector& V); //@} + + /** + * Exception + */ + DeclException2 (ExcInvalidIndex, + int, int, + << "The given index " << arg1 + << " should be less than " << arg2 << "."); + /** + * Exception + */ + DeclException1 (ExcInvalidNumber, + int, + << "The provided number is invalid here: " << arg1); + /** + * Exception + */ + DeclException0 (ExcOutOfMemory); }; @@ -151,13 +170,13 @@ inline int iVector::n() const inline int iVector::operator() (int i) const { -//THROW2( (i<0) || (i>=dim), IntError(IntError::Range,i)); + Assert ((i>=0) || (i=dim), IntError(IntError::Range,i)); + Assert ((i>=0) || (i #include #include #include -#include - - - -DeclException2 (ExcDimensionMismatch, - int, int, - << "The two dimensions " << arg1 << " and " << arg2 - << "do not match here."); -DeclException0 (ExcNotQuadratic); -DeclException0 (ExcInternalError); -DeclException3 (ExcInvalidDestination, - int, int, int, - << "Target region not in matrix: size in this direction=" - << arg1 << ", size of new matrix=" << arg2 - << ", offset=" << arg3); -DeclException1 (ExcNotImplemented, - int, - << "This function is not implemented for the given" - << " matrix dimension " << arg1); diff --git a/deal.II/lac/source/dsmatrix.cc b/deal.II/lac/source/dsmatrix.cc index ec90820a4b..b05430401c 100644 --- a/deal.II/lac/source/dsmatrix.cc +++ b/deal.II/lac/source/dsmatrix.cc @@ -4,8 +4,6 @@ // DEAL is Copyright(1995) by // Roland Becker, Guido Kanschat, Franz-Theo Suttmeier -static const char* OBJFILE = "DEAL $RCSfile$ $Revision$"; - #include #include @@ -120,9 +118,9 @@ inline void quicksort(long r, T* a) void dSMatrixStruct::reinit(int m, int n, int max_per_row) { -// THROW1(m<=0, IntError(IntError::IllegalDimension, m)); -// THROW1(n<=0, IntError(IntError::IllegalDimension, n)); -// THROW1(max_per_row<=0, IntError(IntError::IllegalDimension, max_per_row)); + Assert (m>0, ExcInvalidNumber(m)); + Assert (n>0, ExcInvalidNumber(n)); + Assert (max_per_row>0, ExcInvalidNumber(max_per_row)); rows = m; cols = n; vec_len = m * max_per_row; @@ -204,8 +202,9 @@ dSMatrixStruct::operator () (int i, int j) void dSMatrixStruct::add (int i, int j) { - //THROW1((i<0) || (i>=rows), IntError(IntError::Range,i)); - //THROW1((j<0) || (j>=cols), IntError(IntError::Range,j)); + Assert ((i>=0) && (i=0) && (j #include @@ -16,14 +14,14 @@ dVector::dVector() : val(0) dVector::dVector(int n) : val(0) { + Assert (n>0, ExcInvalidNumber(n)); + dim = n; maxdim = n; - //THROW1(n<0, IntError(IntError::IllegalDimension, n, "dVector")); - if (n) { val = new double[maxdim]; - //THROWUNCOND(!val, Error(Error::NoMem,"dVector::dVector")); + Assert (val != 0, ExcOutOfMemory()); (*this) = 0.; } } @@ -36,19 +34,19 @@ dVector::dVector(const dVector& v) : val(0) if (dim) { val = new double[maxdim]; - //THROWUNCOND(!val, Error(Error::NoMem,"dVector::dVector")); + Assert (val != 0, ExcOutOfMemory()); for (int i=0;i0, ExcInvalidNumber(n)); if (n>maxdim) { if (val) delete[] val; val = new double[n]; - //THROWUNCOND(!val, Error(Error::NoMem,"dVector::reinit")); + Assert (val != 0, ExcOutOfMemory()); maxdim = n; } dim = n; @@ -62,7 +60,7 @@ void dVector::reinit(const dVector& v, int fast) { if (val) delete[] val; val = new double[n]; - //THROWUNCOND(!val, Error(Error::NoMem,"dVector::reinit")); + Assert (val != 0, ExcOutOfMemory()); maxdim = n; } dim = n; @@ -172,8 +170,9 @@ dVector& dVector::operator = (const dVector& v) void dVector::cadd(int i, const VectorBase& V, double s, int j) { const dVector& v = (const dVector&) V; - //THROW1((i<0) || (i>dim), IntError(IntError::Range,i,"cadd")); - //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd")); + + Assert ((i>=0) || (i=0) || (jdim), IntError(IntError::Range,i,"cadd")); - //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd")); - //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cadd")); + + Assert ((i>=0) || (i=0) || (j=0) || (kdim), IntError(IntError::Range,i,"cadd")); - //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cadd")); - //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cadd")); - //THROW1((l<0) || (l>v.dim), IntError(IntError::Range,l,"cadd")); - //THROW1((m<0) || (m>v.dim), IntError(IntError::Range,m,"cadd")); + + Assert ((i>=0) || (i=0) || (j=0) || (k=0) || (l=0) || (mdim), IntError(IntError::Range,i)); - val[i] = 0.; + Assert ((i>=0) && (idim), IntError(IntError::Range,i,"cequ")); - //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ")); + + Assert ((i>=0) && (i=0) && (jdim), IntError(IntError::Range,i,"cequ")); - //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ")); - //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cequ")); + + Assert ((i>=0) || (i=0) || (j=0) || (kdim), IntError(IntError::Range,i,"cequ")); - //THROW1((j<0) || (j>v.dim), IntError(IntError::Range,j,"cequ")); - //THROW1((k<0) || (k>v.dim), IntError(IntError::Range,k,"cequ")); - //THROW1((l<0) || (l>v.dim), IntError(IntError::Range,l,"cequ")); - //THROW1((m<0) || (m>v.dim), IntError(IntError::Range,m,"cequ")); + + Assert ((i>=0) || (i=0) || (j=0) || (k=0) || (l=0) || (m + + iVector::iVector() { dim=maxdim=1; val = new int[1]; - //THROWUNCOND(!val, Error(Error::NoMem,"iVector::iVector")); + Assert (val != 0, ExcOutOfMemory()); val[0] = 0; } iVector::iVector(int n) { + Assert (n>0, ExcInvalidNumber(n)); + dim = n; maxdim = n; - //THROW1(n<=0, IntError(IntError::IllegalDimension, n, "iVector::iVector")); - val = new int[maxdim]; - //THROWUNCOND(!val, Error(Error::NoMem,"iVector::iVector")); + Assert (val != 0, ExcOutOfMemory()); (*this) = 0; } @@ -36,12 +36,12 @@ iVector::iVector(const iVector& v) void iVector::reinit(int n, int fast) { - //THROW1(n<=0, IntError(IntError::IllegalDimension, n, "iVector::reinit")); + Assert (n>0, ExcInvalidNumber(n)); if (n>maxdim) { delete[] val; val = new int[n]; - //THROWUNCOND(!val, Error(Error::NoMem,"iVector::reinit")); + Assert (val != 0, ExcOutOfMemory()); maxdim = n; } dim = n; @@ -55,7 +55,7 @@ void iVector::reinit(const iVector& v, int fast) { delete[] val; val = new int[n]; - //THROWUNCOND(!val, Error(Error::NoMem,"iVector::reinit")); + Assert (val != 0, ExcOutOfMemory()); maxdim = n; } dim = n; -- 2.39.5