public static void unlink(PyObject path) { Path nioPath = absolutePath(path); try { if (Files.isDirectory(nioPath, LinkOption.NOFOLLOW_LINKS)) { throw Py.OSError(Errno.EISDIR, path); } else if (!Files.deleteIfExists(nioPath)) { // Something went wrong, does stat raise an error? basicstat(path, nioPath); // It exists, do we not have permissions? if (!Files.isWritable(nioPath)) { throw Py.OSError(Errno.EACCES, path); } throw Py.OSError("unlink(): an unknown error occurred: " + nioPath.toString()); } } catch (IOException ex) { PyException pyError = Py.OSError("unlink(): an unknown error occurred: " + nioPath.toString()); pyError.initCause(ex); throw pyError; } }
public static PyException JavaError(Throwable t) { if (t instanceof PyException) { return (PyException) t; } else if (t instanceof InvocationTargetException) { return JavaError(((InvocationTargetException) t).getTargetException()); } else if (t instanceof StackOverflowError) { return Py.RuntimeError("maximum recursion depth exceeded (Java StackOverflowError)"); } else if (t instanceof OutOfMemoryError) { memory_error((OutOfMemoryError) t); } else if (t instanceof UserInterruptException) { return Py.KeyboardInterrupt(""); } PyObject exc = PyJavaType.wrapJavaObject(t); PyException pyex = new PyException(exc.getType(), exc); // Set the cause to the original throwable to preserve // the exception chain. pyex.initCause(t); return pyex; }