gx_exception.hpp

Go to the documentation of this file.
00001 #ifndef __gx_exception_hpp__
00002 #define __gx_exception_hpp__
00003 
00004 #include <exception>
00005 
00006 #include <glib.h>
00007 
00008 #include "common/gxerror.h"
00009 #include "common/sh_utils.h"
00010 
00011 NONSHARABLE_CLASS(GException) : 
00012   public std::exception
00013 {
00014  public:
00015   // Argument may be NULL.
00016   GException(GError* aError) : iError(aError) {}
00017 
00018   virtual ~GException() throw () 
00019   {
00020     gx_error_free(iError);
00021   }
00022 
00023   virtual const char *what() const throw ()
00024   {
00025     if (!iError)
00026       return "out of memory error";
00027     return iError->message;
00028   }
00029 
00030   GError* gerror() const { return iError; }
00031 
00032  private:
00033   GError *iError; // owned
00034 };
00035 
00036 #define gx_throw(_error) throw GException(_error)
00037 
00038 #define gx_throw_new(f...) gx_throw(gx_error_new(f))
00039 
00040 #endif /* __gx_exception_hpp__ */
00041 
00042 /**
00043 
00044 Copyright 2010 Helsinki Institute for Information Technology (HIIT)
00045 and the authors. All rights reserved.
00046 
00047 Authors: Tero Hasu <tero.hasu@hut.fi>
00048 
00049 Permission is hereby granted, free of charge, to any person
00050 obtaining a copy of this software and associated documentation files
00051 (the "Software"), to deal in the Software without restriction,
00052 including without limitation the rights to use, copy, modify, merge,
00053 publish, distribute, sublicense, and/or sell copies of the Software,
00054 and to permit persons to whom the Software is furnished to do so,
00055 subject to the following conditions:
00056 
00057 The above copyright notice and this permission notice shall be
00058 included in all copies or substantial portions of the Software.
00059 
00060 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00061 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00062 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00063 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00064 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00065 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00066 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00067 SOFTWARE.
00068 
00069  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:53 2011 by Doxygen 1.6.1