views:

156

answers:

2

Could someone provide info about error-handling in wxWidgets or a pointer to documentation?

Specifically, I discovered this behavior: I try to create a wxImage from a file. This is in an event-handler. The file is not present. The call to the image constructor does not throw an exception. (I understand that no wxWidgets code throws exceptions.) A call to image.Ok() returns false. Fine. But after my event-handler exits, wxWidgets gratuitously pops up an error message dialog. That's okay for this particular application, but I wonder how to stop that from happening if I want to handle the error myself. I suspect that the dialog is coming from an event-handler, but I search for things like EVT_ERROR, and came up empty.

+2  A: 

There is the class wxLogNull for suppressing those log messages. See http://docs.wxwidgets.org/stable/wx_wxlognull.html#wxlognull where also an example is given.

Read the wxLog overview for more details on how wxWidgets handles this.

Johannes Schaub - litb
Thanks. (I think.:-)) Time to read the encyclopedia. From a a glance, it looks a bit convoluted. Oh well. The wxLogNull example looks simple enough, but it would throw away the error message.If I derive a class from wxLog, what function(s) do I want to override? DoLog?
Jive Dadson
If you don't want to throw it away, you can use `wxLogStderr` to output to `stderr`. It's all explained in the wxLog overview. `DoLogString` sounds like what you wanna do for simple things.
Johannes Schaub - litb
What I want is to get as close as possible to the model where a failed operation throws an exception that has an error code or message in it. But it's not urgent. I'll read and study. Thanks again.
Jive Dadson
A: 

You can define your own log target which would throw an exception if an error message is logged. Of course, then you'd probably need to catch it in your event handler anyhow as you probably don't want to just give the user a relatively useless "File couldn't be opened" message but rather a "Image couldn't be opened" one. And if you do this, then why not just test for file.IsOk() directly and use wxLogError() yourself? IOW you can do what you want but I don't really see how is it better than the traditional exception-less way of doing things in this particular case.

VZ