示例#1
0
    def HandleException(self, codeBlock):
        # NOTE - Never returns - raises a ComException
        exc_type, exc_value, exc_traceback = sys.exc_info()
        # If a SERVER exception, re-raise it.  If a client side COM error, it is
        # likely to have originated from the script code itself, and therefore
        # needs to be reported like any other exception.
        if IsCOMServerException(exc_type):
            # Ensure the traceback doesnt cause a cycle.
            exc_traceback = None
            raise
        # It could be an error by another script.
        if (
            issubclass(pythoncom.com_error, exc_type)
            and exc_value.hresult == axscript.SCRIPT_E_REPORTED
        ):
            # Ensure the traceback doesnt cause a cycle.
            exc_traceback = None
            raise Exception(scode=exc_value.hresult)

        exception = error.AXScriptException(
            self, codeBlock, exc_type, exc_value, exc_traceback
        )

        # Ensure the traceback doesnt cause a cycle.
        exc_traceback = None
        result_exception = error.ProcessAXScriptException(
            self.scriptSite, self.debugManager, exception
        )
        if result_exception is not None:
            try:
                self.scriptSite.OnScriptTerminate(None, result_exception)
            except pythoncom.com_error:
                pass  # Ignore errors telling engine we stopped.
            # reset ourselves to 'connected' so further events continue to fire.
            self.SetScriptState(axscript.SCRIPTSTATE_CONNECTED)
            raise result_exception
        # I think that in some cases this should just return - but the code
        # that could return None above is disabled, so it never happens.
        RaiseAssert(
            winerror.E_UNEXPECTED, "Don't have an exception to raise to the caller!"
        )