Exception handling

19 views
Skip to first unread message

Tim Burgess

unread,
May 25, 2012, 5:12:24 AM5/25/12
to wx-u...@googlegroups.com

Hi,

 

I’m trying to implement the catching of an unhandled exception in my own code, based on the except.cpp sample, but not having any luck under VS2010.  My scenario is as follows:

 

1 – I’m using a non-WX serialisation library (Boost) for loading and saving data.  If the loading operation encounters a file with an incorrect format (maybe due to some change in the target class since the last build) an unhandled exception is thrown and it’s this eventuality I want to trap so that I can ignore the file without termination of the application;

 

2 – I have try/catch blocks around the relevant lines of code, but the WX unhandled exception dialog is still triggered;

 

3 – I put the following line in my application’s main .hpp file:

 

#define wxUSE_EXCEPTIONS = 1  

 

Is this correct, please?

 

Best wishes.

 

Tim Burgess

Raised Bar Ltd

Phone:  +44 (0)1827 719822

 

Don't forget to vote for improved access to music and music technology at

 

http://www.raisedbar.net/petition.htm

 

 

Patrick Steele

unread,
May 28, 2012, 5:16:09 AM5/28/12
to wx-u...@googlegroups.com
Hi Tim,
here's an excerpt from my code that will catch a boost::serialization exception, perhaps this might help. If you catch and react to the exception at the point at which it happens, instead of letting it bubble up to wxApp, then you could more accurately react to the problem. You could also add versioning to the serialization through the BOOST_CLASS_VERSION macro and that should prevent an exception happening at all: data would get output and input according to its version.

       //tries to import an .xml formatted changelog file

        std::wstring fileAddress = ...
        std::wifstream inputFileStream( fileAddress.c_str() );

        try
        {
            boost::archive::xml_wiarchive inputXMLArchive( inputFileStream );
            inputXMLArchive >> BOOST_SERIALIZATION_NVP( *this );

            isFileImported = true;
        }
        catch ( const boost::archive::archive_exception& archiveException )
        {
            ...
        }

        inputFileStream.close();

Patrick


--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to wx-users+u...@googlegroups.com
or visit http://groups.google.com/group/wx-users

Reply all
Reply to author
Forward
0 new messages