]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/exceptions.h
add support for persistent controls
[wxWidgets.git] / docs / doxygen / overviews / exceptions.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
3b88355f 2// Name: exceptions.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
880efa2a 9/**
36c9828f 10
928f1a07 11@page overview_exceptions C++ Exceptions
36c9828f 12
928f1a07
FM
13@li @ref overview_exceptions_introduction
14@li @ref overview_exceptions_strategies
15@li @ref overview_exceptions_tech
36c9828f
FM
16
17
928f1a07 18<hr>
3b88355f
FM
19
20
928f1a07 21@section overview_exceptions_introduction Introduction
36c9828f 22
928f1a07
FM
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.
3b88355f 30
928f1a07
FM
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.
36c9828f
FM
35
36
928f1a07 37@section overview_exceptions_strategies Strategies for exceptions handling
36c9828f 38
928f1a07
FM
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.
3b88355f 44
928f1a07
FM
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.
3b88355f 57
928f1a07
FM
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.
36c9828f
FM
65
66
928f1a07 67@section overview_exceptions_tech Technicalities
36c9828f 68
928f1a07
FM
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.
3b88355f 74
928f1a07
FM
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.
36c9828f 78
928f1a07
FM
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.
36c9828f 81
3b88355f 82*/