2 // This file is part of the aMule Project.
4 // Copyright (c) 2005-2008 Mikkel Schubert ( xaignar@users.sourceforge.net )
5 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include <wx/string.h>
32 * Installs an exception handler that can handle CMuleExceptions.
34 void InstallMuleExceptionHandler();
39 void OnUnhandledException();
42 //! Print a backtrace, skipping the first n frames.
43 void print_backtrace(unsigned n
);
45 //! Returns a backtrace, skipping the first n frames.
46 wxString
get_backtrace(unsigned n
);
50 * This exception should be used to implement other
51 * types of exceptions. It should never be caught,
52 * instead catch the subtypes.
57 CMuleException(const wxString
& type
, const wxString
& desc
)
58 : m_what(type
+ wxT(": ") + desc
) {}
59 virtual ~CMuleException() throw() {}
60 virtual const wxString
& what() const throw() { return m_what
; }
68 * This exception type is used to represent exceptions that are
69 * caused by invalid operations. Exceptions of this type should
70 * not be caught as they are the result of bugs.
72 struct CRunTimeException
: public CMuleException
74 CRunTimeException(const wxString
& type
, const wxString
& desc
)
75 : CMuleException(wxT("CRunTimeException::") + type
, desc
) {}
81 * This exception is to be thrown if invalid parameters are passed to a function.
83 struct CInvalidParamsEx
: public CRunTimeException
85 CInvalidParamsEx(const wxString
& desc
)
86 : CRunTimeException(wxT("CInvalidArgsException"), desc
) {}
91 * This exception is to be thrown if an object is used in an invalid state.
93 struct CInvalidStateEx
: public CRunTimeException
95 CInvalidStateEx(const wxString
& desc
)
96 : CRunTimeException(wxT("CInvalidStateException"), desc
) {}
100 * This exception is thrown on wrong packets or tags.
102 struct CInvalidPacket
: public CMuleException
104 CInvalidPacket(const wxString
& desc
)
105 : CMuleException(wxT("CInvalidPacket"), desc
) {}
109 // This ifdef ensures that we wont get assertions while
110 // unittesting, which would otherwise impede the tests.
112 #define _MULE_THROW(cond, cls, msg) \
119 #define _MULE_THROW(cond, cls, msg) \
122 wxFAIL_MSG(wxT(#cond)); \
130 #define MULE_CHECK_THROW(cond, cls, msg) \
131 _MULE_THROW((cond), cls, (msg))
133 #define MULE_VALIDATE_STATE(cond, msg) \
134 MULE_CHECK_THROW((cond), CInvalidStateEx, (msg))
136 #define MULE_VALIDATE_PARAMS(cond, msg) \
137 MULE_CHECK_THROW((cond), CInvalidParamsEx, (msg))
140 #define MULE_ASSERT(cond) wxASSERT((cond))
141 #define MULE_ASSERT_MSG(cond, msg) wxASSERT_MSG((cond), msg)
142 #define MULE_FAIL() wxFAIL()
143 #define MULE_FAIL_MSG(msg) wxFAIL_MSG(msg)
144 #define MULE_CHECK(cond, retValue) wxCHECK((cond), (retValue))
145 #define MULE_CHECK_MSG(cond, ret, msg) wxCHECK_MSG((cond), (ret), (msg))
146 #define MULE_CHECK_RET(cond, msg) wxCHECK_RET((cond), (msg))
149 // File_checked_for_headers