public static void CallbackException(Exception e, CodeContext /*!*/ context) { PythonContext pc = PythonContext.GetContext(context); object stderr = pc.SystemStandardError; PythonOps.PrintWithDest(context, stderr, pc.FormatException(e)); }
public static void excepthook(CodeContext /*!*/ context, object exctype, object value, object traceback) { PythonContext pc = PythonContext.GetContext(context); PythonOps.PrintWithDest( context, pc.SystemStandardError, pc.FormatException(PythonExceptions.ToClr(value)) ); }
public static void excepthookImpl(CodeContext /*!*/ context, object exctype, object value, object traceback) { PythonContext pc = context.LanguageContext; var exc = PythonExceptions.ToClr(value); if (exc is null) { throw PythonOps.TypeError($"Exception expected for {nameof(value)}, {PythonTypeOps.GetName(value)} found"); } PythonOps.PrintWithDest( context, pc.SystemStandardError, pc.FormatException(PythonExceptions.ToClr(value)) ); }
//Our implementation of WinSignalsHandler public bool WindowsEventHandler(uint winSignal) { bool retVal; int pySignal; switch (winSignal) { case CTRL_C_EVENT: pySignal = SIGINT; break; case CTRL_BREAK_EVENT: pySignal = SIGBREAK; break; case CTRL_CLOSE_EVENT: pySignal = SIGBREAK; break; case CTRL_LOGOFF_EVENT: pySignal = SIGBREAK; break; case CTRL_SHUTDOWN_EVENT: pySignal = SIGBREAK; break; default: throw new Exception("unreachable"); } lock (PySignalToPyHandler) { if (PySignalToPyHandler[pySignal].GetType() == typeof(int)) { int tempId = (int)PySignalToPyHandler[pySignal]; if (tempId == SIG_DFL) { //SIG_DFL - we let Windows do whatever it normally would retVal = false; } else if (tempId == SIG_IGN) { //SIG_IGN - we do nothing, but tell Windows we handled the signal retVal = true; } else { throw new Exception("unreachable"); } } else if (PySignalToPyHandler[pySignal] == default_int_handler) { if (pySignal != SIGINT) { //We're dealing with the default_int_handlerImpl which we //know doesn't care about the frame parameter retVal = true; default_int_handlerImpl(pySignal, null); } else { //Let the real interrupt handler throw a KeyboardInterrupt for SIGINT. //It handles this far more gracefully than we can retVal = false; } } else { //We're dealing with a callable matching PySignalHandler's signature retVal = true; PySignalHandler temp = (PySignalHandler)Converter.ConvertToDelegate(PySignalToPyHandler[pySignal], typeof(PySignalHandler)); try { if (SignalPythonContext.PythonOptions.Frames) { temp.Invoke(pySignal, SysModule._getframeImpl(null, 0, SignalPythonContext._mainThreadFunctionStack)); } else { temp.Invoke(pySignal, null); } } catch (Exception e) { System.Console.WriteLine(SignalPythonContext.FormatException(e)); } } } return(retVal); }