开发者

Error handling in wxWidgets

开发者 https://www.devze.com 2022-12-21 04:22 出处:网络
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.

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 e开发者_开发百科vent-handler, but I search for things like EVT_ERROR, and came up empty.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消