java - 与try和catch相关的异常处理

标签 java

我们可以在catch block 中编写任何实现代码吗? catch block 中要使用哪些规则来实现?

try{
    resultado = (T) mensaje.getBody(clase);

}
catch(Exception ex){
    resultado = null;
    this.destruye();
    throw ex;
}

最佳答案

您可以在 catch block 中编写您想要的所有代码。

Exception handlers can do more than just print error messages or halt the program. They can do error recovery, prompt the user to make a decision, or propagate the error up to a higher-level handler using chained exception

请记住,只有抛出异常时才会执行此代码。

关于java - 与try和catch相关的异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30476273/

相关文章:

java - 使用按钮的 onClickListener 更改 textview 上的文本

java - org.hibernate.exception.JDBCConnectionException : Could not open connection when open a transcation

java - 通过名称获取 Swing 组件

java - 使用 @CrossOrigin 时不显示 CORS 响应 header

java - java中的集合、子集和回文

Java FX-8 : Why is EventType generic?

java - 在 Stream.generate().forEach() 中找不到方法

java - 错误 : Could not find or load main class HelloWorld

java - 本教程中的 @color/cream_dark 是什么?

java - 为什么在 SortedSet 中查找 headSet 时附加空字符 "\0"?