简体   繁体   中英

How to get a specific section in a message exception in java?

I need to know how to get a specific section of an message generated by an exception in java, in debug mode, I have obtained the value I need, which attached image, but I need get that data in the code to generate a "Switch", I require something like this:

在此处输入图片说明

try 
{

processes .... 

} catch (SQLException ex) {

string reason = ex.**(how to get the failure reason)**; 

switch (reason) {

           case "_bt_check_unique": 

                       JOptionPane.showMessageDialog (null, "Error, the record already exists."); 

           break; 

} 

您将要在异常对象上调用getStackTrace() ,然后在返回的数组中的StackTraceElement对象上使用各种getter方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM