Error.h

Go to the documentation of this file.
00001 //# Error.h: Base class for all AIPS++ errors
00002 //# Copyright (C) 1993,1994,1995,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef CASA_ERROR_H
00029 #define CASA_ERROR_H
00030 
00031 
00032 
00033 #include <sys/types.h>
00034 #include <casa/aips.h>
00035 #include <casa/BasicSL/String.h>
00036 #include <exception>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // <summary>Base class for all AIPS++ library errors</summary>
00041 // <use visibility=export>
00042 //
00043 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00044 // </reviewed>
00045 //
00046 // <prerequisite>
00047 //   <li> ExcpError
00048 // </prerequisite>
00049 //
00050 // <synopsis>
00051 //  This is the base class for all of the AIPS++ error classes. Because
00052 //  all of the errors have a common base class, any error can be caught
00053 //  with a single catch statement.
00054 //
00055 //  This class has a string which allows error messages to be propagated.
00056 //
00057 //  <note role=tip> The string member must be handled very carefully because
00058 //        string is also derived from cleanup, thus the 
00059 //        <src>message.makePermanent()</src> call in the implementation of
00060 //        the constructors. This prevents the String from being cleaned up
00061 //        in the middle of an exception.
00062 //        </note>
00063 //
00064 // </synopsis>
00065 //
00066 // <example>
00067 // <srcblock>
00068 //      throw(AipsError("SOME STRING"));
00069 // </srcblock>
00070 // </example>
00071 //
00072 // <todo asof="">
00073 // </todo>
00074 
00075 class AipsError: public std::exception
00076 {
00077 public:
00078 
00079   enum Category {
00080     BOUNDARY, INITIALIZATION, INVALID_ARGUMENT, CONFORMANCE,
00081     ENVIRONMENT, SYSTEM, PERMISSION, GENERAL
00082   };
00083 
00084   //
00085   // Simply returns the stored error message.
00086   //
00087   virtual const char* what() const throw()
00088   { return(message.c_str()); }
00089   const String &getMesg() const
00090     { return(message); }
00091   const AipsError::Category getCategory( ) const
00092     { return(category); }
00093 
00094   //
00095   // Creates an AipsError and initializes the error message from
00096   // the parameter
00097   // <group>
00098   AipsError (const Char *str, Category c = GENERAL);
00099   AipsError (const String &str, Category c = GENERAL);
00100   AipsError (Category c = GENERAL) : message(), category(c) {};
00101   // </group>
00102 
00103   //
00104   // Destructor which does nothing.
00105   //
00106   ~AipsError() throw();
00107 
00108 protected:
00109   String message;
00110   Category category;
00111 
00112 };
00113 
00114 
00115 // <summary>Allocation errors</summary>
00116 // <use visibility=export>
00117 //
00118 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00119 // </reviewed>
00120 //
00121 // <synopsis>
00122 //
00123 // This class is used for allocation errors. It adds an extra
00124 // data item, the failed allocation size. Otherwise much the
00125 // same as <src>AipsError</src>.
00126 //
00127 // </synopsis>
00128 //
00129 // <example>
00130 // <srcblock>
00131 //     throw(AllocError("ANY STRING",1024));
00132 // </srcblock>
00133 // </example>
00134 //
00135 // <todo asof="">
00136 // </todo>
00137 
00138 class AllocError : public AipsError {
00139 protected:
00140   size_t Size;
00141 public:
00142   //
00143   // This constructor takes the error message and the failed
00144   // allocation size.
00145   //
00146   // <group>
00147   AllocError(const Char *str, uInt sze) : AipsError(str,SYSTEM), Size(sze) {}
00148   AllocError(const String &str, uInt sze) : AipsError(str,SYSTEM), Size(sze)  {}
00149   // </group>
00150 
00151   //
00152   // This function returns the failed allocation size.
00153   //
00154   size_t size() {return(Size);}
00155 
00156   //
00157   // Destructor which does nothing.
00158   //
00159   ~AllocError() throw();
00160 
00161 };
00162 
00163 
00164 // <summary>Base class for all indexing errors</summary>
00165 // <use visibility=export>
00166 //
00167 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00168 // </reviewed>
00169 //
00170 // <synopsis>
00171 // This class is the base class of all <src>IndexError</src>s. It is
00172 // defined to allow the user to catch any of the many kinds of IndexErrors
00173 // which may be thrown. It can also be thrown itself if returning
00174 // the illegal index value is unimportant.
00175 // </synopsis>
00176 //
00177 // <example>
00178 // <srcblock>
00179 //     throw(IndexError("ANY STRING"));
00180 // </srcblock>
00181 // </example>
00182 //
00183 // <todo asof="">
00184 // </todo>
00185 
00186 class IndexError : public AipsError {
00187 public:
00188   //
00189   // Creates an GeneralIndexError and initializes the error message from
00190   // the parameter
00191   // <group>
00192   IndexError(const Char *str,Category c=BOUNDARY) : AipsError(str,c) {}
00193   IndexError(const String &str,Category c=BOUNDARY) : AipsError(str,c) {}
00194   IndexError(Category c=BOUNDARY) : AipsError(c) {}
00195   // </group>
00196 
00197   //
00198   // Destructor which does nothing.
00199   //
00200   ~IndexError() throw();
00201 };
00202 
00203 
00204 // <summary>Index errors returning the bad index</summary>
00205 // <use visibility=export>
00206 //
00207 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00208 // </reviewed>
00209 //
00210 // <synopsis>
00211 // This class is templated to allow generalalized indexes to be returned
00212 // with the error message i.e. the class is templated on the index type.
00213 //
00214 // </synopsis>
00215 //
00216 // <example>
00217 // <srcblock>
00218 //     throw(indexError<int>(3,"ANY STRING"));/
00219 // </srcblock>
00220 // </example>
00221 //
00222 // <todo asof="">
00223 // </todo>
00224 
00225 template<class t> class indexError : public IndexError {
00226 protected:
00227   t oIndex;                 // Offending Index
00228 public:
00229   //
00230   // This constructor takes the error message and the index
00231   // which cause the error to occur.
00232   //
00233   // <group>
00234   indexError(t oI, const Char *str, Category c=BOUNDARY);
00235   indexError(t oI, const String &str, Category c=BOUNDARY);
00236   indexError(t oI, Category c=BOUNDARY) : IndexError(c), oIndex(oI) {};
00237   // </group>
00238 
00239   //
00240   // Destructor which does nothing.
00241   //
00242   ~indexError() throw();
00243 };
00244 
00245 
00246 // <summary>Duplicate key errors</summary>
00247 // <use visibility=export>
00248 //
00249 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00250 // </reviewed>
00251 //
00252 // <synopsis>
00253 // This class is the base class of all duplicate key errors. It is
00254 // defined to allow the user to catch any of the many kinds of DuplErrors
00255 // which may be thrown. It can also be thrown itself if returning
00256 // the illegal key is unimportant.
00257 // </synopsis>
00258 //
00259 // <example>
00260 // <srcblock>
00261 //    throw(DuplError("ANY STRING"));
00262 // </srcblock>
00263 // </example>
00264 //
00265 // <todo asof="">
00266 // </todo>
00267 
00268 class DuplError : public AipsError {
00269 public:
00270   //
00271   // Creates an DuplError and initializes the error message from
00272   // the parameter
00273   // <group>
00274   DuplError(Category c=BOUNDARY) : AipsError(c) {}
00275   DuplError(const Char *str,Category c=BOUNDARY) : AipsError(str,c) {}
00276   DuplError(const String &str,Category c=BOUNDARY) : AipsError(str,c) {}
00277   // </group>
00278 
00279   //
00280   // Destructor which does nothing.
00281   //
00282   ~DuplError() throw();
00283 };
00284 
00285 
00286 // <summary>Duplicate key errors where the bad key is returned</summary>
00287 // <use visibility=export>
00288 //
00289 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00290 // </reviewed>
00291 //
00292 // <synopsis>
00293 //  This template is for generalized duplicate key errors where the template
00294 //  type parameter is the type of the key which caused the error. Because this
00295 //  class is derived from <linkto class=DuplError><src>DuplError</src>
00296 //  </linkto>, the user to catch all duplicate key errors with one catch
00297 //  statement. 
00298 //
00299 // </synopsis>
00300 //
00301 // <example>
00302 //     throw(duplError<int>(4,"ANY STRING"));
00303 // </example>
00304 //
00305 // <todo asof="">
00306 // </todo>
00307 
00308 template<class t> class duplError : public DuplError {
00309 protected:
00310   t oKey;                   // Offending Key
00311 public:
00312   //
00313   // This constructs a "duplError" for the offending key, and an
00314   // optional character string.
00315   //
00316   // <group>
00317   duplError(t oI, const Char *str,Category c=BOUNDARY);
00318   duplError(t oI, const String &str,Category c=BOUNDARY);
00319   duplError(t oI,Category c=BOUNDARY) : DuplError(c), oKey(oI) {};
00320   // </group>
00321 
00322   //
00323   // Destructor which does nothing.
00324   //
00325   ~duplError() throw();
00326 };
00327 
00328 
00329 // <summary>Exception which halts execution</summary>
00330 // <use visibility=export>
00331 //
00332 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00333 // </reviewed>
00334 //
00335 // <synopsis>
00336 // This error causes an execution to halt regardless. It
00337 // causes execution to halt before the exception can be caught.
00338 // </synopsis>
00339 //
00340 // <example>
00341 // <srcblock>
00342 //     throw(AbortError("ANY STRING"));
00343 // </srcblock>
00344 // </example>
00345 //
00346 // <todo asof="">
00347 // </todo>
00348 
00349 class AbortError : public AipsError {
00350 public:
00351   //
00352   // This constructs a "AbortError" from the error message.
00353   //
00354   // <group>
00355   AbortError(const Char *str,Category c=GENERAL);
00356   AbortError(const String &str,Category c=GENERAL);
00357   // </group>
00358 
00359   //
00360   // Destructor which does nothing.
00361   //
00362   ~AbortError() throw();
00363 };
00364 
00365 
00366 
00367 } //# NAMESPACE CASA - END
00368 #ifdef AIPS_NEEDS_RETHROW
00369 #define RETHROW(X) throw(X);
00370 #else
00371 #define RETHROW(X)
00372 #endif
00373 
00374 #ifndef AIPS_NO_TEMPLATE_SRC
00375 #include <casa/Exceptions/Error.cc>
00376 #include <casa/Exceptions/Error2.cc>
00377 #endif //# AIPS_NO_TEMPLATE_SRC
00378 #endif

Generated on Mon Sep 1 22:33:48 2008 for NRAOCASA by  doxygen 1.5.1