Exception.h

Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/Exception.h,v 1.3 2005/06/13 14:30:17 eraxxon Exp $
00003 
00004 // * BeginCopyright *********************************************************
00005 // *********************************************************** EndCopyright *
00006 
00007 //***************************************************************************
00008 //
00009 // File:
00010 //   $Source: /Volumes/cvsrep/developer/OpenADFortTk/src/Exception.h,v $
00011 //
00012 // Purpose:
00013 //    [The purpose of this file]
00014 //
00015 // Description:
00016 //    [The set of functions, macros, etc. defined in the file]
00017 //
00018 //***************************************************************************
00019 
00020 #ifndef FortTk_Exception_H 
00021 #define FortTk_Exception_H
00022 
00023 //************************* System Include Files ****************************
00024 
00025 #include <iostream>
00026 #include <sstream>
00027 #include <string>
00028 
00029 //*************************** User Include Files ****************************
00030 
00031 //*************************** Forward Declarations ***************************
00032 
00033 //****************************************************************************
00034 
00035 // Note: Use the inteface in "Diagnostics.h"
00036 
00037 //****************************************************************************
00038 // Exception
00039 //****************************************************************************
00040 
00041 namespace fortTkSupport {
00042 
00043   class BaseException {
00044   public:
00045     BaseException() { }
00046     virtual ~BaseException() { }
00047     
00048     virtual const std::string& GetMessage() const = 0;
00049     virtual void Report(std::ostream& os) const = 0;
00050     virtual void Report() const = 0;
00051   };
00052 
00053   // A generic FortTk exception with file/line information
00054   class Exception : public BaseException {
00055   public:
00056     Exception(const char* m,
00057               const char* filenm = NULL, unsigned int lineno = 0);
00058     Exception(std::string m,
00059               const char* filenm = NULL, unsigned int lineno = 0);
00060     virtual ~Exception();
00061     
00062     virtual const std::string& GetMessage() const { return msg; }
00063     virtual void Report(std::ostream& os) const { 
00064       os << "OpenADFortTk::Exception: " << msg << std::endl;
00065     }
00066     virtual void Report() const { Report(std::cerr); }
00067 
00068   private:
00069     void Ctor(std::string& m, 
00070               const char* filenm = NULL, unsigned int lineno = 0);
00071     
00072     std::string msg;
00073   };
00074 
00075   // A fatal FortTk exception that generally should be unrecoverable
00076   class FatalException : public Exception {
00077   public:
00078     FatalException(const char* m,
00079                    const char* filenm = NULL, unsigned int lineno = 0);
00080     FatalException(std::string m,
00081                    const char* filenm = NULL, unsigned int lineno = 0);
00082     virtual ~FatalException();
00083     
00084     virtual void Report(std::ostream& os) const { 
00085       os << "OpenADFortTk::FatalException: " << GetMessage() << std::endl;
00086     }
00087     virtual void Report() const { Report(std::cerr); }
00088 
00089   };
00090   
00091 } /* namespace FortTk */
00092 
00093 //****************************************************************************
00094 
00095 #endif // FortTk_Exception_H

Generated on Fri Jul 24 04:29:02 2009 for OpenADFortTk (extended to Open64) by  doxygen 1.5.7.1