try/catch doesn't catch wxWidgets exception

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
ValeV

try/catch doesn't catch wxWidgets exception

Post by ValeV »

Code: Select all

    wxTreeItemId parent;
    wxTreeItemId focusedItem = TreeCtrl1->GetFocusedItem();
    wxString clicked_structure = TreeCtrl1->GetItemText(focusedItem);
    parent = TreeCtrl1->GetItemParent(focusedItem);
    try
    {
        wxString s = TreeCtrl1->GetItemText(parent);
    }
    catch(...)
    {
        wxMessageBox("CATCH-A-BALL");
        return;
    }
If the focusedItem's parent is virtual root, the code doesn't catch the exception ("can't retrieve virtual root item").

How can I fix it? I Tried parent.isOK(), but it does nothing.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: try/catch doesn't catch wxWidgets exception

Post by doublemax »

wxWidgets doesn't throw C++ exceptions.

You could check if the parent is the root item (wxTreeCtrl::GetRootItem() )
Use the source, Luke!
ValeV

Re: try/catch doesn't catch wxWidgets exception

Post by ValeV »

Thank you, using GetRootItem() works a-ok.
Post Reply