]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/private/error.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / gtk / private / error.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/private/error.h
3 // Purpose: Wrapper around GError.
4 // Author: Vadim Zeitlin
5 // Created: 2012-07-25
6 // Copyright: (c) 2012 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_GTK_PRIVATE_ERROR_H_
11 #define _WX_GTK_PRIVATE_ERROR_H_
12
13 // ----------------------------------------------------------------------------
14 // wxGtkError wraps GError and releases it automatically.
15 // ----------------------------------------------------------------------------
16
17 // Create an object of this class and pass the result of its Out() method to a
18 // function taking "GError**", then use GetMessage() if the function returned
19 // false.
20 class wxGtkError
21 {
22 public:
23 wxGtkError() { m_error = NULL; }
24 ~wxGtkError() { if ( m_error ) g_error_free(m_error); }
25
26 GError** Out()
27 {
28 // This would result in a GError leak.
29 wxASSERT_MSG( !m_error, wxS("Can't reuse the same object.") );
30
31 return &m_error;
32 }
33
34 wxString GetMessage() const
35 {
36 return wxString::FromUTF8(m_error->message);
37 }
38
39 private:
40 GError* m_error;
41
42 wxDECLARE_NO_COPY_CLASS(wxGtkError);
43 };
44
45 #endif // _WX_GTK_PRIVATE_ERROR_H_