source/bases/Win32GUI.c
//-----------------------------------------------------------------------------
// FatalScriptError()
//   Handle a fatal Python error with traceback.
//-----------------------------------------------------------------------------
FatalScriptError()
Handle a fatal Python error with traceback.
FatalScriptError () Handle a fatal Python error with traceback .
static int FatalScriptError()
{
    PyObject *type, *value, *traceback, *argsTuple, *module, *method, *result;
    PyObject *caption, *hook, *origHook, *emptyString, *message;
    if (PyErr_ExceptionMatches(PyExc_SystemExit))
        return HandleSystemExitException();
    PyErr_Fetch(&type, &value, &traceback);
    PyErr_NormalizeException(&type, &value, &traceback);
    argsTuple = PyTuple_New(3);
    if (!argsTuple)
        return FatalPythonErrorNoTraceback(value, "Cannot create args tuple.");
    PyTuple_SET_ITEM(argsTuple, 0, ArgumentValue(type));
    PyTuple_SET_ITEM(argsTuple, 1, ArgumentValue(value));
    PyTuple_SET_ITEM(argsTuple, 2, ArgumentValue(traceback));
    hook = PySys_GetObject("excepthook");
    origHook = PySys_GetObject("__excepthook__");
    if (hook && hook != origHook) {
        result = PyObject_CallObject(hook, argsTuple);
        if (!result)
            return FatalPythonErrorNoTraceback(value,
                    "Error in sys.excepthook.");
        return -1;
    }
    module = PyImport_ImportModule("traceback");
    if (!module)
        return FatalPythonErrorNoTraceback(value,
                "Cannot import traceback module.");
    method = PyObject_GetAttrString(module, "format_exception");
    if (!method)
        return FatalPythonErrorNoTraceback(value,
              "Cannot get format_exception method.");
    result = PyObject_CallObject(method, argsTuple);
    if (!result)
        return FatalPythonErrorNoTraceback(value,
                "Exception raised when calling format_exception.");
    emptyString = PyUnicode_FromString("");
    if (!emptyString)
        return FatalPythonErrorNoTraceback(value,
                "Cannot create empty string object.");
    message = PyUnicode_Join(emptyString, result);
    if (!message)
        return FatalPythonErrorNoTraceback(value,
                "Cannot join exception strings.");
    caption = PyObject_GetAttrString(value, "caption");
    if (!caption || !PyUnicode_Check(caption)) {
        PyErr_Clear();
        caption = PyUnicode_FromString("cx_Freeze: Python error in main script");
        if (!caption)
            return FatalPythonErrorNoTraceback(value,
                    "Cannot create default caption string.");
    }
    return DisplayMessageFromPythonObjects(caption, message);
}
static int FatalScriptError ( ) { PyObject * type , * value , * traceback , * argsTuple , * module , * method , * result ; PyObject * caption , * hook , * origHook , * emptyString , * message ; if ( PyErr_ExceptionMatches ( PyExc_SystemExit ) ) return HandleSystemExitException ( ) ; PyErr_Fetch ( & type , & value , & traceback ) ; PyErr_NormalizeException ( & type , & value , & traceback ) ; argsTuple = PyTuple_New ( 3 ) ; if ( ! argsTuple ) return FatalPythonErrorNoTraceback ( value , " " ) ; PyTuple_SET_ITEM ( argsTuple , 0 , ArgumentValue ( type ) ) ; PyTuple_SET_ITEM ( argsTuple , 1 , ArgumentValue ( value ) ) ; PyTuple_SET_ITEM ( argsTuple , 2 , ArgumentValue ( traceback ) ) ; hook = PySys_GetObject ( " " ) ; origHook = PySys_GetObject ( " " ) ; if ( hook && hook != origHook ) { result = PyObject_CallObject ( hook , argsTuple ) ; if ( ! result ) return FatalPythonErrorNoTraceback ( value , " " ) ; return -1 ; } module = PyImport_ImportModule ( " " ) ; if ( ! module ) return FatalPythonErrorNoTraceback ( value , " " ) ; method = PyObject_GetAttrString ( module , " " ) ; if ( ! method ) return FatalPythonErrorNoTraceback ( value , " " ) ; result = PyObject_CallObject ( method , argsTuple ) ; if ( ! result ) return FatalPythonErrorNoTraceback ( value , " " ) ; emptyString = PyUnicode_FromString ( " " ) ; if ( ! emptyString ) return FatalPythonErrorNoTraceback ( value , " " ) ; message = PyUnicode_Join ( emptyString , result ) ; if ( ! message ) return FatalPythonErrorNoTraceback ( value , " " ) ; caption = PyObject_GetAttrString ( value , " " ) ; if ( ! caption || ! PyUnicode_Check ( caption ) ) { PyErr_Clear ( ) ; caption = PyUnicode_FromString ( " " ) ; if ( ! caption ) return FatalPythonErrorNoTraceback ( value , " " ) ; } return DisplayMessageFromPythonObjects ( caption , message ) ; }
FatalScriptError()
Handle a fatal Python error with traceback.
FatalScriptError () Handle a fatal Python error with traceback .
// if a system exception, handle it specially // get the exception details // call the exception hook // import the traceback module // get the format_exception method // call the format_exception method // convert to string // acquire caption // display message box