~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/cbexception.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 
3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 
4
 */
 
5
 
 
6
#ifndef CBEXCEPTION_H
 
7
#define CBEXCEPTION_H
 
8
 
 
9
#include <wx/string.h>
 
10
#include <wx/log.h> // for wxSafeShowMessage()
 
11
 
 
12
/**
 
13
@brief Code::Blocks error handling unit.
 
14
 
 
15
Two macros are defined to help error handling in Code::Blocks:
 
16
cbThrow() and cbAssert().
 
17
@note cbAssert() does nothing in release mode. For debug mode, compile with -DcbDEBUG
 
18
*/
 
19
 
 
20
/** @brief The base Code::Blocks exception object. */
 
21
class cbException
 
22
{
 
23
    public:
 
24
        cbException(const wxString& msg, const wxString& file, int line);
 
25
        virtual ~cbException();
 
26
 
 
27
        /** @brief Display exception error message.
 
28
          * @param safe If true, wxSafeShowMessage will be used to display the error,
 
29
          *             else a normal message box will be used.
 
30
          */
 
31
        void ShowErrorMessage(bool safe = true);
 
32
 
 
33
        // public members
 
34
        wxString Message; ///< The exception's error message.
 
35
        wxString File; ///< The file where the exception was raised.
 
36
        int Line; ///< The line in the file where the exception was raised.
 
37
};
 
38
 
 
39
#if wxUSE_UNICODE
 
40
    #define cbThrow(message) throw cbException(message, cbC2U(__FILE__), __LINE__)
 
41
#else
 
42
    #define cbThrow(message) throw cbException(message, __FILE__, __LINE__)
 
43
#endif
 
44
 
 
45
#ifndef cbDEBUG
 
46
    #define cbAssert(expr)
 
47
#else
 
48
    // In unix we use kill to terminate the application, that makes gdb
 
49
    // keep it alive which makes debugging easier.
 
50
    // (thanks go to an unknown author)
 
51
    #ifdef __WXMSW__
 
52
        #define DIE() exit(1)
 
53
    #else
 
54
        #include <csignal>
 
55
        #define DIE() kill(0, SIGTERM)
 
56
    #endif
 
57
 
 
58
    #if wxUSE_UNICODE
 
59
        #define cbAssertMessage(expr) \
 
60
            wxString err; \
 
61
            err.Printf(_T("Assertion failed in %s at %s:%d.\n\n%s"), cbC2U(__PRETTY_FUNCTION__).c_str(), cbC2U(__FILE__).c_str(), __LINE__, cbC2U(#expr).c_str());
 
62
    #else
 
63
        #define cbAssertMessage(expr) \
 
64
            wxString err; \
 
65
            err.Printf(_T("Assertion failed in %s at %s:%d.\n\n%s"), __PRETTY_FUNCTION__, __FILE__, __LINE__, #expr);
 
66
    #endif
 
67
 
 
68
    // non-fatal assertion
 
69
    #define cbAssertNonFatal(expr) \
 
70
        if (!(expr)) \
 
71
        { \
 
72
            cbAssertMessage(expr); \
 
73
            wxSafeShowMessage(_T("Assertion error"), err); \
 
74
        }
 
75
 
 
76
    // fatal assertion
 
77
    #define cbAssert(expr) \
 
78
        if (!(expr)) \
 
79
        { \
 
80
            cbAssertMessage(expr); \
 
81
            wxSafeShowMessage(_T("Fatal assertion error"), err); \
 
82
            DIE(); \
 
83
        }
 
84
#endif
 
85
 
 
86
#endif // CBEXCEPTION_H