public String getShortDescription() { return cause.toString(); }
public CannotCreateException(Exception e) { super("by " + e.toString()); } }
public ObjectNotFoundException(String name, Exception e) { super(name + " because of " + e.toString()); } }
public RemoteException(Exception e) { super("by " + e.toString()); } }
public NotFoundException(String msg, Exception e) { super(msg + " because of " + e.toString()); } }
/** Render the object passed as parameter by calling its <code>toString</code> method. */ public String doRender(final Object o) { try { return o.toString(); } catch(Exception ex) { return ex.toString(); } } }
@Override public String toString() { StringWriter result = new StringWriter().append( super.toString() ); for ( Diagnostic<?> diagnostic : diagnostics ) { format( result.append( "\n\t\t" ), diagnostic ); } return result.toString(); }
private void introspectWriteReplace(Class cl, ClassLoader loader) { try { String className = cl.getName() + "HessianSerializer"; Class serializerClass = Class.forName(className, false, loader); Object serializerObject = serializerClass.newInstance(); Method writeReplace = getWriteReplace(serializerClass, cl); if (writeReplace != null) { _writeReplaceFactory = serializerObject; _writeReplace = writeReplace; return; } } catch (ClassNotFoundException e) { } catch (Exception e) { log.log(Level.FINER, e.toString(), e); } _writeReplace = getWriteReplace(cl); }
private void introspectWriteReplace(Class cl, ClassLoader loader) { try { String className = cl.getName() + "HessianSerializer"; Class serializerClass = Class.forName(className, false, loader); Object serializerObject = serializerClass.newInstance(); Method writeReplace = getWriteReplace(serializerClass, cl); if (writeReplace != null) { _writeReplaceFactory = serializerObject; _writeReplace = writeReplace; return; } } catch (ClassNotFoundException e) { } catch (Exception e) { log.log(Level.FINER, e.toString(), e); } _writeReplace = getWriteReplace(cl); }
@Override @Nullable public String getMessage() { if (ObjectUtils.isEmpty(this.messageExceptions)) { return super.getMessage(); } else { StringBuilder sb = new StringBuilder(); String baseMessage = super.getMessage(); if (baseMessage != null) { sb.append(baseMessage).append(". "); } sb.append("Failed messages: "); for (int i = 0; i < this.messageExceptions.length; i++) { Exception subEx = this.messageExceptions[i]; sb.append(subEx.toString()); if (i < this.messageExceptions.length - 1) { sb.append("; "); } } return sb.toString(); } }
/** * Build a descriptive exception message for the given JMSException, * incorporating a linked exception's message if appropriate. * @param ex the JMSException to build a message for * @return the descriptive message String * @see javax.jms.JMSException#getLinkedException() */ public static String buildExceptionMessage(JMSException ex) { String message = ex.getMessage(); Exception linkedEx = ex.getLinkedException(); if (linkedEx != null) { if (message == null) { message = linkedEx.toString(); } else { String linkedMessage = linkedEx.getMessage(); if (linkedMessage != null && !message.contains(linkedMessage)) { message = message + "; nested exception is " + linkedEx; } } } return message; }
/** * Obtains the default value represented by this attribute. */ public MemberValue getDefaultValue() { try { return new AnnotationsAttribute.Parser(info, constPool) .parseMemberValue(); } catch (Exception e) { throw new RuntimeException(e.toString()); } }
private void assertIsCompiled(Expression expression) { try { Field field = SpelExpression.class.getDeclaredField("compiledAst"); field.setAccessible(true); Object object = field.get(expression); assertNotNull(object); } catch (Exception ex) { fail(ex.toString()); } }
/** * Validates that the given class, when forcefully instantiated throws * an IllegalArgumentException("No instances!") exception. * @param clazz the class to test, not null */ public static void checkUtilityClass(Class<?> clazz) { try { Constructor<?> c = clazz.getDeclaredConstructor(); c.setAccessible(true); try { c.newInstance(); fail("Should have thrown InvocationTargetException(IllegalStateException)"); } catch (InvocationTargetException ex) { assertEquals("No instances!", ex.getCause().getMessage()); } } catch (Exception ex) { AssertionError ae = new AssertionError(ex.toString()); ae.initCause(ex); throw ae; } }
@Test public void testIncorrectOutputSize() throws Exception { final File inFile = new File("pom.xml"); final File outFile = new ShorterFile("target/pom.tmp"); // it will report a shorter file try { FileUtils.copyFile(inFile, outFile); fail("Expected IOException"); } catch (final Exception e) { final String msg = e.toString(); assertTrue(msg, msg.contains("Failed to copy full contents")); } finally { outFile.delete(); // tidy up } }
@Test public void testTripleElection() throws Exception { try{ runElection(3); } catch (Exception e) { Assert.fail(e.toString()); } }
@Test public void testSingleElection() throws Exception { try{ runElection(1); } catch (Exception e) { Assert.fail(e.toString()); } }
private ClientHttpResponse getClientHttpResponse( HttpMethod httpMethod, URI uri, HttpHeaders requestHeaders, byte[] requestBody) { try { MockHttpServletResponse servletResponse = this.mockMvc .perform(request(httpMethod, uri).content(requestBody).headers(requestHeaders)) .andReturn() .getResponse(); HttpStatus status = HttpStatus.valueOf(servletResponse.getStatus()); byte[] body = servletResponse.getContentAsByteArray(); MockClientHttpResponse clientResponse = new MockClientHttpResponse(body, status); clientResponse.getHeaders().putAll(getResponseHeaders(servletResponse)); return clientResponse; } catch (Exception ex) { byte[] body = ex.toString().getBytes(StandardCharsets.UTF_8); return new MockClientHttpResponse(body, HttpStatus.INTERNAL_SERVER_ERROR); } }
@Test // SPR-16132 public void followUpRequestAfterFailure() { MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build(); server.expect(requestTo("/some-service/some-endpoint")) .andRespond(request -> { throw new SocketException("pseudo network error"); }); server.expect(requestTo("/reporting-service/report-error")) .andExpect(method(POST)).andRespond(withSuccess()); try { this.restTemplate.getForEntity("/some-service/some-endpoint", String.class); } catch (Exception ex) { this.restTemplate.postForEntity("/reporting-service/report-error", ex.toString(), String.class); } server.verify(); }