Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

FatalException.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 ////////////////////////////////////////////////////////////////////
00003 //
00004 // Filename : FatalException (base)
00005 //
00006 // This file is a part of the UPPAAL toolkit.
00007 // Copyright (c) 1995 - 2003, Uppsala University and Aalborg University.
00008 // All right reserved.
00009 //
00010 // $Id: FatalException.h,v 1.1 2004/02/16 14:09:11 adavid Exp $
00011 //
00012 ///////////////////////////////////////////////////////////////////
00013 
00014 #ifndef INCLUDE_BASE_FATALEXCEPTION_H
00015 #define INCLUDE_BASE_FATALEXCEPTION_H
00016 
00017 #include <iostream>
00018 #include <exception>
00019 
00020 namespace base
00021 {
00022     /** Fatal exception: something fatal
00023      * (and forbidden) has happened.
00024      */
00025     class FatalException : public std::exception
00026     {
00027     public:
00028 
00029         /** Constructor:
00030          * @param whichone: which fatal event has happened.
00031          */
00032         FatalException(const char *whichone) throw()
00033             : message(whichone) {}
00034 
00035         /** Overrides exception::what()
00036          */
00037         virtual const char* what() const throw();
00038 
00039     private:
00040         const char *message;
00041     };
00042 
00043     /** Overload operator <<
00044      */
00045     static inline
00046     std::ostream& operator << (std::ostream& os,
00047                                const FatalException& x)
00048     {
00049         return os << x.what();
00050     }
00051 
00052 } // namespace base
00053 
00054 /** Macros for convenience:
00055  * print & throw fatal exception.
00056  */
00057 #define FATAL(MSG) do {            \
00058   std::cerr << "Fatal exception: " \
00059             << MSG << std::endl;   \
00060   throw base::FatalException(MSG); \
00061 } while(0)
00062 
00063 #endif // INCLUDE_BASE_FATAL_EXCEPTION

Generated on Fri Jun 30 00:02:30 2006 for Module base by  doxygen 1.4.2