wxWidgets and memory allocation failures.

Jurko Gospodnetić jurko_for_boost at mail.inet.hr
Tue Apr 10 09:24:36 PDT 2007


   Hi.

>  It doesn't. wxWidgets doesn't use exceptions itself but new can still
> throw.

   Wow... that does not seem right.

   If this is really 'by design' (and I hope it is not :-)) then that 
should noted in the documentation instead of simply stating 'the library 
doesn't throw exceptions to signal about the errors' or 'the library 
doesn't throw any exceptions by itself and so you don't have to worry 
about exceptions at all unless your own code throws them.'.

   If new operator calls used inside wxWidgets code may throw 
std::bad_alloc then this should be documented as it affects external 
wxWidgets interfaces accessible to the user. Saying 'we don't throw but 
some things we call may throw' seems wrong as then the user is expected 
to know your internal implementation details in order to be prepared for 
any exceptions that may be thrown from wxWidgets code.

   Technique I use for this, and the one I would strongly suggest for 
wxWidgets, is to document all possible exception throws in all the 
functions (at least public ones, but I found not way to keep these up to 
date without maintaining such specifications for all my functions). I do 
not use formal C++ exception specifications but use standardized 
function comments listing all the exceptions that may be thrown by their 
corresponding function.

   Without this wxWidgets is 'lying' to the user and saying 'when you 
call my functions no exceptions will come back at you except for 
possibly those thrown by your own code' while what it actually means is 
'when you call my functions no exception will come back at you except 
for possibly those thrown by your code or those thrown by my internal 
implementation details but which I do not document'. Operator new can 
hardly be considered 'application code'.


   Hope this helps...

   Best regards,
     Jurko Gospodnetić





More information about the wx-users mailing list