VirtualBox

Changeset 41214 in vbox for trunk/src/VBox/Main/src-all


Ignore:
Timestamp:
May 8, 2012 5:59:43 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
77853
Message:

Main: move handleUnexpectedExceptions method to VirtualBoxBase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/VirtualBoxBase.cpp

    r41184 r41214  
    2020#include <iprt/semaphore.h>
    2121#include <iprt/asm.h>
     22#include <iprt/cpp/exception.h>
     23
     24#include <typeinfo>
    2225
    2326#if !defined (VBOX_WITH_XPCOM)
     
    292295
    293296    AssertMsgFailed (("mState = %d!", mState));
     297}
     298
     299/**
     300 * Handles unexpected exceptions by turning them into COM errors in release
     301 * builds or by hitting a breakpoint in the release builds.
     302 *
     303 * Usage pattern:
     304 * @code
     305        try
     306        {
     307            // ...
     308        }
     309        catch (LaLalA)
     310        {
     311            // ...
     312        }
     313        catch (...)
     314        {
     315            rc = VirtualBox::handleUnexpectedExceptions(this, RT_SRC_POS);
     316        }
     317 * @endcode
     318 *
     319 * @param aThis             object where the exception happened
     320 * @param RT_SRC_POS_DECL   "RT_SRC_POS" macro instantiation.
     321 *  */
     322/* static */
     323HRESULT VirtualBoxBase::handleUnexpectedExceptions(VirtualBoxBase *const aThis, RT_SRC_POS_DECL)
     324{
     325    try
     326    {
     327        /* re-throw the current exception */
     328        throw;
     329    }
     330    catch (const RTCError &err)      // includes all XML exceptions
     331    {
     332        return setErrorInternal(E_FAIL, aThis->getClassIID(), aThis->getComponentName(),
     333                                Utf8StrFmt(tr("%s.\n%s[%d] (%s)"),
     334                                           err.what(),
     335                                           pszFile, iLine, pszFunction).c_str(),
     336                                false /* aWarning */,
     337                                true /* aLogIt */);
     338    }
     339    catch (const std::exception &err)
     340    {
     341        return setErrorInternal(E_FAIL, aThis->getClassIID(), aThis->getComponentName(),
     342                                Utf8StrFmt(tr("Unexpected exception: %s [%s]\n%s[%d] (%s)"),
     343                                           err.what(), typeid(err).name(),
     344                                           pszFile, iLine, pszFunction).c_str(),
     345                                false /* aWarning */,
     346                                true /* aLogIt */);
     347    }
     348    catch (...)
     349    {
     350        return setErrorInternal(E_FAIL, aThis->getClassIID(), aThis->getComponentName(),
     351                                Utf8StrFmt(tr("Unknown exception\n%s[%d] (%s)"),
     352                                           pszFile, iLine, pszFunction).c_str(),
     353                                false /* aWarning */,
     354                                true /* aLogIt */);
     355    }
     356
     357    /* should not get here */
     358    AssertFailed();
     359    return E_FAIL;
    294360}
    295361
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette