|
OpenADFortTk (basic)
|
00001 // ########################################################## 00002 // # This file is part of OpenADFortTk. # 00003 // # The full COPYRIGHT notice can be found in the top # 00004 // # level directory of the OpenADFortTk source tree. # 00005 // # For more information visit # 00006 // # http://www.mcs.anl.gov/openad # 00007 // ########################################################## 00008 00009 #ifndef FortTk_Exception_H 00010 #define FortTk_Exception_H 00011 00012 #include <iostream> 00013 #include <sstream> 00014 #include <string> 00015 00016 00017 namespace fortTkSupport { 00018 00019 class BaseException { 00020 public: 00021 BaseException() { } 00022 virtual ~BaseException() { } 00023 00024 virtual const std::string& GetMessage() const = 0; 00025 virtual void Report(std::ostream& os) const = 0; 00026 virtual void Report() const = 0; 00027 }; 00028 00029 // A generic FortTk exception with file/line information 00030 class Exception : public BaseException { 00031 public: 00032 Exception(const char* m, 00033 const char* filenm = NULL, unsigned int lineno = 0); 00034 Exception(std::string m, 00035 const char* filenm = NULL, unsigned int lineno = 0); 00036 virtual ~Exception(); 00037 00038 virtual const std::string& GetMessage() const { return msg; } 00039 virtual void Report(std::ostream& os) const { 00040 os << "OpenADFortTk::Exception: " << msg << std::endl; 00041 } 00042 virtual void Report() const { Report(std::cerr); } 00043 00044 private: 00045 void Ctor(std::string& m, 00046 const char* filenm = NULL, unsigned int lineno = 0); 00047 00048 std::string msg; 00049 }; 00050 00051 // A fatal FortTk exception that generally should be unrecoverable 00052 class FatalException : public Exception { 00053 public: 00054 FatalException(const char* m, 00055 const char* filenm = NULL, unsigned int lineno = 0); 00056 FatalException(std::string m, 00057 const char* filenm = NULL, unsigned int lineno = 0); 00058 virtual ~FatalException(); 00059 00060 virtual void Report(std::ostream& os) const { 00061 os << "OpenADFortTk::FatalException: " << GetMessage() << std::endl; 00062 } 00063 virtual void Report() const { Report(std::cerr); } 00064 00065 }; 00066 00067 } 00068 00069 #endif // FortTk_Exception_H