Handling exceptions in wxApp constructor Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Dischster
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 09, 2016 7:54 pm

Handling exceptions in wxApp constructor

Post by Dischster » Sun Jun 12, 2016 4:32 pm

My wxApp derived class has an object that may throw an exception in its constructor, in which case I would want to post a message box to report the error and immediately close the program.

However, I don't know how to catch this exception. I'm using wxIMPLEMENT_APP to instantiate my wxApp object.... and OnExceptionInMainLoop and OnUnhandledException won't work because they depend on the wxApp object being fully constructed.

My current workaround is to allocate the object dynamically in OnInit and catch the exception there -- but is there another way?

Thanks.

User avatar
T-Rex
Moderator
Moderator
Posts: 1199
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Handling exceptions in wxApp constructor

Post by T-Rex » Sun Jun 12, 2016 5:14 pm

Looks like current workaround is the best way to do the initialization.
I assume that you can use wxIMPLEMENT_APP_NO_MAIN and then implement the main() function manually, but allocation in OnInit() still looks reasonable,

Dischster
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 09, 2016 7:54 pm

Re: Handling exceptions in wxApp constructor

Post by Dischster » Tue Jun 14, 2016 4:50 am

Alright. That's what I figured, but I thought I'd check to be sure.

Thanks!

Post Reply