]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/doxygen/overviews/exceptions.h
correct a typo in wxSplitterWindow gravity parameter name
[wxWidgets.git] / docs / doxygen / overviews / exceptions.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: exceptions.h
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10
11@page overview_exceptions C++ Exceptions
12
13@li @ref overview_exceptions_introduction
14@li @ref overview_exceptions_strategies
15@li @ref overview_exceptions_tech
16
17
18<hr>
19
20
21@section overview_exceptions_introduction Introduction
22
23wxWidgets had been started long before the exceptions were introduced in C++ so
24it is not very surprising that it is not built around using them as some more
25modern C++ libraries are. For instance, the library doesn't throw exceptions to
26signal about the errors. Moreover, up to (and including) the version 2.4 of
27wxWidgets, even using the exceptions in the user code was dangerous because the
28library code wasn't exception-safe and so an exception propagating through it
29could result in memory and/or resource leaks, and also not very convenient.
30
31wxWidgets is exception-friendly.
32It still doesn't use the exceptions by itself but it should be now safe to use the
33exceptions in the user code and the library tries to help you with this. Please
34note that making the library exception-safe is still work in progress.
35
36
37@section overview_exceptions_strategies Strategies for exceptions handling
38
39There are several choice for using the exceptions in wxWidgets programs. First
40of all, you may not use them at all. As stated above, the library doesn't throw
41any exceptions by itself and so you don't have to worry about exceptions at all
42unless your own code throws them. This is, of course, the simplest solution but
43may be not the best one to deal with all possible errors.
44
45Another strategy is to use exceptions only to signal truly fatal errors. In
46this case you probably don't expect to recover from them and the default
47behaviour -- to simply terminate the program -- may be appropriate. If it is
48not, you may override wxApp::OnUnhandledException()
49in your wxApp-derived class to perform any clean up tasks. Note, however, that
50any information about the exact exception type is lost when this function is
51called, so if you need you should override wxApp::OnRun() and
52add a try/catch clause around the call of the base class version. This would
53allow you to catch any exceptions generated during the execution of the main
54event loop. To deal with the exceptions which may arise during the program
55startup and/or shutdown you should insert try/catch clauses in
56wxApp::OnInit() and/or wxApp::OnExit() as well.
57
58Finally, you may also want to continue running even when certain exceptions
59occur. If all of your exceptions may happen only in the event handlers of a
60single class (or only in the classes derived from it), you may centralize your
61exception handling code in wxApp::ProcessEvent
62method of this class. If this is impractical, you may also consider overriding
63the wxApp::HandleEvent() which allows you to handle
64all the exceptions thrown by any event handler.
65
66
67@section overview_exceptions_tech Technicalities
68
69To use any kind of exception support in the library you need to build it
70with @c wxUSE_EXCEPTIONS set to 1. This should be the case by default but
71if it isn't, you should edit the @c include/wx/msw/setup.h file under
72Windows or run @c configure with @c --enable-exceptions argument
73under Unix.
74
75On the other hand, if you do not plan to use exceptions, setting this
76flag to 0 or using @c --disable-exceptions could result in a leaner and
77slightly faster library.
78
79As for any other library feature, there is a sample (@c except)
80showing how to use it. Please look at its sources for further information.
81
82*/