如何在java中的消息异常中获取特定部分?

时间:2014-06-05 16:35:06

标签: java

我需要知道如何在java中获取由异常生成的消息的特定部分,在调试模式下,我已经获得了我需要的值,附加了图像,但我需要在代码中获取该数据以生成一个“开关”,我需要这样的东西:

enter image description here

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; 

} 

1 个答案:

答案 0 :(得分:1)

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