Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

general_exception.hpp

00001 // general_exception.hpp
00002 
00003 // Copyright (C) 2004 Steven Weiß (steven11@gmx.de)
00004 //
00005 // Permission to copy, use, sell and distribute this software is granted
00006 // provided this copyright notice appears in all copies.
00007 // Permission to modify the code and to distribute modified code is granted
00008 // provided this copyright notice appears in all copies, and a notice
00009 // that the code was modified is included with the copyright notice.
00010 //
00011 // This software is provided "as is" without express or implied warranty,
00012 // and with no claim as to its suitability for any purpose.
00013 
00014 
00015 #pragma once
00016 #include <background_wnd/detail/include.hpp>
00017 
00018 
00019 /* 
00020 The exception-hierarchy presented here is serveral layers:
00021      - To catch all exceptions of background_wnd and the painters catch background_wnd_exception
00022      - To catch all exceptions of a specific class catch general_exception_of_type<class_name>
00023      - To catch a specific exception of a class catch general_exception<class_name, exception_number> 
00024        (most likely this will be typedef'ed in the class)
00025 */
00026 
00027 namespace win32 { namespace gui {
00028 namespace bg_wnd {
00029 
00033      struct background_wnd_exception : std::exception
00034      {
00035           background_wnd_exception() : std::exception("Exception caused by background_wnd or a painter")
00036           {}
00037      };
00038 
00039 
00047      template<class T>
00048      class general_exception_of_type : public background_wnd_exception
00049      {
00050           const T& obj_;
00051      public:
00052           typedef T class_type;
00053 
00054           general_exception_of_type(const T& obj) : obj_(obj)
00055           {}
00056           
00057           const T& get_object() const
00058           {
00059                return obj_;
00060           }
00061      };
00062 
00071      template <class T, int num>
00072      struct general_exception : general_exception_of_type<T>
00073      {                   
00074           general_exception(const T& obj) : general_exception_of_type<T> (obj)
00075           {}   
00076      };
00077 
00078 }    // namespace bg_wnd
00079 } }  // namespace win32::gui



by Steven Weiss. You can contact me at steven11@gmx.de.