@Override public Error getCause() { return (Error) super.getCause(); } }
if (e.getCause() instanceof IOException) {
@Test public void testCatchErrorInProcessFilesMethod() throws Exception { // The idea of the test is to satisfy coverage rate. // An Error indicates serious problems that a reasonable application should not try to // catch, but due to issue https://github.com/checkstyle/checkstyle/issues/2285 // we catch errors in 'processFiles' method. Most such errors are abnormal conditions, // that is why we use PowerMockito to reproduce them. final File mock = PowerMockito.mock(File.class); // Assume that I/O error is happened when we try to invoke 'lastModified()' method. final String errorMessage = "Java Virtual Machine is broken" + " or has run out of resources necessary for it to continue operating."; final Error expectedError = new IOError(new InternalError(errorMessage)); when(mock.lastModified()).thenThrow(expectedError); final Checker checker = new Checker(); final List<File> filesToProcess = new ArrayList<>(); filesToProcess.add(mock); try { checker.process(filesToProcess); fail("IOError is expected!"); } // -@cs[IllegalCatchExtended] Testing for catch Error is part of 100% coverage. catch (Error error) { assertThat("Error cause differs from IOError", error.getCause(), instanceOf(IOError.class)); assertThat("Error cause is not InternalError", error.getCause().getCause(), instanceOf(InternalError.class)); assertEquals("Error message is not expected", errorMessage, error.getCause().getCause().getMessage()); } }
@Override public synchronized SQLException getCause() { return (SQLException) super.getCause(); }
@Override public Error getCause() { return (Error) super.getCause(); } }
@Override public SQLException getCause() { return (SQLException) super.getCause(); }
/** * 13.14 The try Statement * * @param e * the error cause * @return if either <var>e</var> or its cause is a stack overflow error, that error object * @throws Error * if neither the error nor its cause is a stack overflow error */ public static StackOverflowError stackOverflowError(Error e) throws Error { if (e instanceof StackOverflowError) { return (StackOverflowError) e; } if (e instanceof BootstrapMethodError) { Throwable cause = e.getCause(); if (cause instanceof StackOverflowError) { return (StackOverflowError) cause; } } throw e; }
@Override public Error getCause() { return Validate.isInstanceOf(Error.class, super.getCause(), "Unexpected cause type."); } }
@Override public Error getCause() { return Validate.isInstanceOf(Error.class, super.getCause(), "Unexpected cause type."); } }
@Override @Ignore public java.lang.Throwable getCause() { return super.getCause(); }
private void bindImpl(SocketAddress addr) throws IOException { try { bindImpl2(addr); } catch(Error e) { //NOTE: jdk was throwing Error instead of BindException. We fix //this and throw BindException which is the logical choice!! //We are crossing our fingers hoping there are not other SocketExceptions //from things other than address already in use!!! if(e.getCause() instanceof SocketException) { BindException exc = new BindException(e.getMessage()); exc.initCause(e.getCause()); throw exc; } throw e; } }
@Override public Throwable getCause() { if (true) new MineField(e.getMessage(), e); rethrowThisMaybe(); return super.getCause(); }
@Override public List<String> getPortIdentifiers() { List<String> portIdentifiers = new ArrayList<>(); try { // get the comm port identifiers portIdentifiers.addAll(serialPortFactory.getPortNames(true)); } catch (UnsatisfiedLinkError ule) { LOGGER.warn("Get comm port identifiers failed.", ule); throw new InvalidLibraryException(ule.getMessage(), ule.getCause()); } catch (Error error) { LOGGER.warn("Get comm port identifiers failed.", error); throw new RuntimeException(error.getMessage(), error.getCause()); } return portIdentifiers; }
/** * Will poll the interface on a regular basis until at least one element is present. */ public List<WebElement> findElements() { if (aPreviousStepHasFailed()) { return EMPTY_LIST_OF_WEBELEMENTS; } SlowLoadingElementList list = new SlowLoadingElementList(clock, annotatedTimeoutInSeconds.or(timeOutInSeconds)); try { return list.get().getElements(); } catch (Error e) { throw new NoSuchElementException( String.format("Timed out after %d seconds. %s", annotatedTimeoutInSeconds.or(timeOutInSeconds), e.getMessage()), e.getCause()); } }
@Override public synchronized Throwable getCause() { if(!MockFramework.isEnabled()){ return super.getCause(); } return getDelegate().getCause(); }
private Application build() throws Exception { Application app = null; Exception exception = null; // if we get a bind exception, then retry a few times (may conflict with parallel test runs) for (int i = 0; i < 5; i++) { try { generateXml(); app = new Application(path, networking, true); break; } catch (Error e) { // the container thinks this is really serious, in this case is it not in the cause is a BindException // catch bind error and reset container Optional<BindException> bindException = Exceptions.findCause(e, BindException.class); if (bindException.isPresent()) { exception = bindException.get(); com.yahoo.container.Container.resetInstance(); // this is needed to be able to recreate the container from config again } else { throw new Exception(e.getCause()); } } } if (app == null) { throw exception; } return app; }
/** * Will poll the interface on a regular basis until at least one element is present. */ public List<WebElement> findElements() { if (aPreviousStepHasFailed()) { return EMPTY_LIST_OF_WEBELEMENTS; } SlowLoadingElementList list = new SlowLoadingElementList(clock, annotatedTimeoutInSeconds.orElse(getTimeOutInSeconds())); try { return list.get().getElements(); } catch (Error e) { throw new NoSuchElementException( String.format("Timed out after %d seconds. %s", annotatedTimeoutInSeconds.orElse(getTimeOutInSeconds()), e.getMessage()), e.getCause()); } }
public void write(final DataOutput out) throws IOException { WritableUtils.writeVInt(out, getNumberOfPointers()); try { this.forEachTerm(new TObjectIntProcedure<String>() { public boolean execute(String term, int freq) { try{ Text.writeString(out, term); WritableUtils.writeVInt(out, freq); } catch (IOException e) { throw new Error(e); } return true; } }); } catch (Error e) { throw (IOException)e.getCause(); } }
/** * Returns the XML for a generic error. * * @param ex The error to turn to XML. * @param xml The XML writer. * @param wrap Whether to wrap the XML into an element. * * @throws IOException Only if thrown by the XML writer. */ private static void asErrorXML(Error ex, XMLWriter xml, boolean wrap) throws IOException { if (wrap) { xml.openElement("error"); } xml.attribute("class", ex.getClass().getName()); xml.element("message", cleanMessage(ex)); xml.element("stack-trace", OXErrors.getStackTrace(ex, true)); Throwable cause = ex.getCause(); if (cause != null) { xml.openElement("cause"); toXML(cause, xml, false); xml.closeElement(); } if (wrap) { xml.closeElement(); } }
@JRubyMethod public IRubyObject bind(IRubyObject host, IRubyObject port) { InetSocketAddress addr = null; try { if (host.isNil()) { addr = new InetSocketAddress(RubyNumeric.fix2int(port)); } else { addr = new InetSocketAddress(InetAddress.getByName(host.convertToString().toString()), RubyNumeric.fix2int(port)); } ((DatagramChannel) this.getChannel()).socket().bind(addr); return RubyFixnum.zero(this.getRuntime()); } catch (UnknownHostException e) { throw sockerr(this, "bind: name or service not known"); } catch (SocketException e) { throw sockerr(this, "bind: name or service not known"); } catch (Error e) { // Workaround for a bug in Sun's JDK 1.5.x, see // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6303753 if (e.getCause() instanceof SocketException) { throw sockerr(this, "bind: name or service not known"); } else { throw e; } } }