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