Java - find the first cause of an exception

后端 未结 10 986
渐次进展
渐次进展 2020-12-09 01:50

I need to check if an exception is caused by some database problem. I receive an Exception and check if its cause contains the \"ORA\" string and return that (something like

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 02:24

    you can use the getStackTrace() from the Throwable class. This would give you the stack of StackTraceElements to work with. You can iterate through the StackTraceElements[] to find "ORA" string.

    Let me know if you need an example.

提交回复
热议问题