java.lang.Exception.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(395)

本文整理了Java中java.lang.Exception.toString()方法的一些代码示例,展示了Exception.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exception.toString()方法的具体详情如下:
包路径:java.lang.Exception
类名称:Exception
方法名:toString

Exception.toString介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

public String getShortDescription() {
  return cause.toString();
}

代码示例来源:origin: redisson/redisson

public String toString() {
    if (e == null)
      return super.toString();
    else
      return e.toString();
  }
}

代码示例来源:origin: redisson/redisson

public CannotCreateException(Exception e) {
    super("by " + e.toString());
  }
}

代码示例来源:origin: redisson/redisson

public ObjectNotFoundException(String name, Exception e) {
    super(name + " because of " + e.toString());
  }
}

代码示例来源:origin: redisson/redisson

public RemoteException(Exception e) {
    super("by " + e.toString());
  }
}

代码示例来源:origin: redisson/redisson

public NotFoundException(String msg, Exception e) {
    super(msg + " because of " + e.toString());
  }
}

代码示例来源:origin: log4j/log4j

/**
   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();
     }
 }
}

代码示例来源:origin: neo4j/neo4j

@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();
}

代码示例来源:origin: apache/incubator-dubbo

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);
}

代码示例来源:origin: apache/incubator-dubbo

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);
}

代码示例来源:origin: spring-projects/spring-framework

@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();
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * 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;
}

代码示例来源:origin: redisson/redisson

/**
 * 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());
  }
}

代码示例来源:origin: spring-projects/spring-framework

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());
  }
}

代码示例来源:origin: ReactiveX/RxJava

/**
 * 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;
  }
}

代码示例来源:origin: commons-io/commons-io

@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
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testTripleElection() throws Exception {
  try{
    runElection(3);
  } catch (Exception e) {
    Assert.fail(e.toString());
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testSingleElection() throws Exception {
  try{
    runElection(1);
  } catch (Exception e) {
    Assert.fail(e.toString());
  }
}

代码示例来源:origin: spring-projects/spring-framework

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);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@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();
}

相关文章