开发者

custom exception and parsing message from exception

ex.Message = "ORA-20586: SOME TEXT SOME TEXT.\nORA-06512: at \"RMM.LOKAC\", line 116\nORA-06512: at line 2"

catch (Exception ex)
    MessageBox.Show(ex.Message);
    return false;
}

ex.Message = "ORA-20586: SOME TEXT SOME TEXT.\nORA-06512: at \"RMM.LOKAC\", line 116\nORA-06512: at line 2"

but i need to get just "SOME TEXT SOME TEXT". How can i read just text.

ORA-20586 means user error http://www.dbmotive.com/support/oracle-error-codes/?type=ORA&errcode=20586

Database is Oracle. How can i read j开发者_JAVA技巧ust "SOME TEXT SOME TEXT" from this error message.


There are number of ways to extract the string. You may try String split, regular expression split or string index search.


It is always better to catch the exception, then write a more user friendly message. You never want to expose the underlying architecture of your application, if possible.

bool success = false;
try {
  // you code
  success = true; // Notice: Last call of  your try routine.
} catch (Exception ex {
  if (-1 < ex.Message.IndexOf("ORA-20586")) {
    MessageBox.Show("user error");
  } else {
    MessageBox.Show(ex.Message);
  }
}
return success;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜