Java - find the first cause of an exception

后端 未结 10 991
渐次进展
渐次进展 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:29

    Just traverse the exception chain until you get to an exception with no cause, and then just return that message, if you want the last one.

    Your function will only get the first cause, if there is one.

    You may want to look at finding the first cause in your package though, as the actual deepest one may be an oracle exception, which is helpful, but unless you can see where you created the problem, you will have a hard time fixing it.

提交回复
热议问题