public static PyException setException(Throwable t, PyFrame frame) { PyException pye = Py.JavaError(t); pye.normalize(); pye.tracebackHere(frame); getThreadState().exception = pye; return pye; }
/** * Invoke a user-defined error-handling mechanism, for errors encountered during encoding, as * registered through {@link #register_error(String, PyObject)}. The return value is the return * from the error handler indicating the replacement codec <b>input</b> and the the position at * which to resume encoding. Invokes the mechanism described in PEP-293. * * @param errors name of the error policy (or null meaning "strict") * @param encoding name of encoding that encountered the error * @param toEncode unicode string being encoded * @param start index of first char it couldn't encode * @param end index+1 of last char it couldn't encode (usually becomes the resume point) * @param reason contribution to error message if any * @return must be a tuple <code>(replacement_unicode, resume_index)</code> */ public static PyObject encoding_error(String errors, String encoding, String toEncode, int start, int end, String reason) { // Retrieve handler registered through register_error(). null is equivalent to "strict". PyObject errorHandler = lookup_error(errors); // Construct an exception to hand to the error handler PyException exc = Py.UnicodeEncodeError(encoding, toEncode, start, end, reason); exc.normalize(); // And invoke the handler. PyObject replacement = errorHandler.__call__(new PyObject[] {exc.value}); checkErrorHandlerReturn(errors, replacement); return replacement; }
/** * Invoke a user-defined error-handling mechanism, for errors encountered during decoding, as * registered through {@link #register_error(String, PyObject)}. The return value is the return * from the error handler indicating the replacement codec <b>output</b> and the the position at * which to resume decoding. Invokes the mechanism described in PEP-293. * * @param errors name of the error policy (or null meaning "strict") * @param encoding name of encoding that encountered the error * @param toDecode bytes being decoded * @param start index of first byte it couldn't decode * @param end index+1 of last byte it couldn't decode (usually becomes the resume point) * @param reason contribution to error message if any * @return must be a tuple <code>(replacement_unicode, resume_index)</code> */ public static PyObject decoding_error(String errors, String encoding, String toDecode, int start, int end, String reason) { // Retrieve handler registered through register_error(). null is equivalent to "strict". PyObject errorHandler = lookup_error(errors); // Construct an exception to hand to the error handler PyException exc = Py.UnicodeDecodeError(encoding, toDecode, start, end, reason); exc.normalize(); // And invoke the handler. PyObject replacementSpec = errorHandler.__call__(new PyObject[] {exc.value}); checkErrorHandlerReturn(errors, replacementSpec); return replacementSpec; }
exceptHook.__call__(exc.type, exc.value, exc.traceback); } catch (PyException exc2) { exc2.normalize(); flushLine(); stderr.println("Error in sys.excepthook:");
pye.normalize(); if (!isExceptionInstance(pye.value)) { throw Py.TypeError(String.format(
private static ScriptException scriptException(PyException pye) { ScriptException se = null; try { pye.normalize();
PyException exc = ts.exception; if (b.b_type == Opcode.SETUP_EXCEPT) { exc.normalize();