使用java中的finally块捕获其消息的异常

Sau*_*oid 1 java exception-handling try-catch-finally

我有以下代码,我喜欢使用最终获得异常消息,因为通过使用catch我可以很容易地通过它的arg.but我知道我无法使用finally获取异常消息.

try {
 MyClass obj=new MyClass();
 obj.strProName = jobj1.getString("productname");
 obj.strPrice = jobj1.getString("price");
 obj.strCurrency = jobj1.getString("currency");
 obj.strSalePrice = jobj1.getString("saleprice");
 obj.strStoreName = jobj1.getString("storename");

//arrayList.add(obj);
throw new Exception("Exception Reason!");

}
finally{
 //want to get that exception message here without using catch or can see how finally catching here the exception
}
Run Code Online (Sandbox Code Playgroud)

Sur*_*tta 6

不像catch block,finally块没有接收任何exception实例

所以,我的答案是否定的.

我的意思是打印消息,你需要Exception实例.

根据文件(jls-14.2)

块是大括号内的语句,本地类声明和局部变量声明语句的序列.

所以在catch块之外 catch(Exception e) {} 你无法访问它(e).