Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Exception.hh

Go to the documentation of this file.
00001 // $Id: Exception.hh 1780 2011-04-07 13:26:06Z jmo $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Utils_Exception_
00027 #define HH_SENF_Utils_Exception_ 1
00028 
00029 // Custom includes
00030 #include <exception>
00031 #include <string>
00032 #include <iostream>
00033 #include <sstream>
00034 #include <boost/preprocessor/repeat.hpp>
00035 #include <boost/preprocessor/cat.hpp>
00036 #include <boost/utility.hpp>
00037 #include <boost/type_traits/is_convertible.hpp>
00038 #include <senf/config.hh>
00039 
00040 //#include "Exception.mpp"
00041 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00042 
00132 namespace senf {
00133 
00141     class ExceptionMixin
00142     {
00143     public:
00144         std::string message() const; 
00145         std::string backtrace() const; 
00146 
00147         void append(std::string text);  
00148 
00150     protected:
00151         explicit ExceptionMixin(std::string const & description = "");
00153 
00158         std::string what_;
00159     private:
00160 #ifdef SENF_BACKTRACE
00161         void addBacktrace();
00162 #endif
00163 #ifdef SENF_DEBUG
00164         std::string::size_type excLen_;
00165 #endif
00166     };
00167 
00178     class Exception
00179         : public ExceptionMixin, public std::exception
00180     {
00181     public:
00182         virtual ~Exception() throw();
00183 
00184         virtual char const * what() const throw();
00186 
00189     protected:
00190         explicit Exception(std::string const & description = "");
00191     };
00192 
00200     template <class BaseException>
00201     class WrapException
00202         : public ExceptionMixin, public BaseException
00203     {
00204     public:
00205         typedef BaseException Base;
00206 
00207         WrapException(BaseException const & base);
00208         virtual ~WrapException() throw();
00209 
00210         virtual char const * what() const throw();
00211     };
00212 
00220 #   define SENF_WRAP_EXC(Ex)                                                                      \
00221         catch (Ex const & base) {                                                                 \
00222             if (dynamic_cast<senf::ExceptionMixin const *>(&base))                                \
00223                 throw;                                                                            \
00224             else                                                                                  \
00225                 throw senf::WrapException<Ex>(base);                                              \
00226         }
00227 
00228     template <class Exc, class Arg>
00229     typename boost::enable_if< boost::is_convertible<Exc*,ExceptionMixin*>, Exc & >::type
00230     operator<<(Exc const & exc, Arg const & arg); 
00231 
00239 #   ifdef SENF_DEBUG
00240 #       define _SENF_EXC_DEBUG_ARGS ,char const * file=0,int line=0
00241 #       define _SENF_EXC_DEBUG_ARGS_ND ,char const *file,int line
00242 #       define _SENF_EXC_DEBUG_ARGS_P ,file,line
00243 #   else
00244 #       define _SENF_EXC_DEBUG_ARGS
00245 #       define _SENF_EXC_DEBUG_ARGS_ND
00246 #       define _SENF_EXC_DEBUG_ARGS_P
00247 #   endif
00248 
00281     class SystemException : public Exception
00282     {
00283     public:
00284         //-////////////////////////////////////////////////////////////////////////
00286         //\{
00287 
00288         explicit SystemException(std::string const & descr = "" _SENF_EXC_DEBUG_ARGS);
00289         explicit SystemException(int code _SENF_EXC_DEBUG_ARGS);
00290         SystemException(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS);
00291 
00292         virtual ~SystemException() throw();
00293 
00294         //\}
00295         //-////////////////////////////////////////////////////////////////////////
00296 
00297         int errorNumber() const;        
00298         char const * errorString() const; 
00299 
00300         bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0,
00301                    int c6=0, int c7=0, int c8=0, int c9=0) const;
00303 
00304     private:
00305         void init(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS_ND);
00306 
00307         int code_;
00308     };
00309 
00310 #   ifdef SENF_DEBUG
00311 #       define SENF_EXC_DEBUGINFO ,__FILE__,__LINE__
00312 #   else
00313 #       define SENF_EXC_DEBUGINFO
00314 #   endif
00315 
00316 #   define SENF_THROW_SYSTEM_EXCEPTION(desc) throw senf::SystemException(desc SENF_EXC_DEBUGINFO)
00317 
00318 }
00319 
00320 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00321 #include "Exception.cci"
00322 //#include "Exception.ct"
00323 #include "Exception.cti"
00324 #endif
00325 
00326 
00327 // Local Variables:
00328 // mode: c++
00329 // fill-column: 100
00330 // c-file-style: "senf"
00331 // indent-tabs-mode: nil
00332 // ispell-local-dictionary: "american"
00333 // compile-command: "scons -u test"
00334 // comment-column: 40
00335 // End:
00336 

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research