Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify which function call threw a particular exception in a try block?

Let's say there are three consecutive function calls in one try block and all of them throw the same type of exception. How can i figure out which function call threw the caught exception when handling it?

like image 504
dirtybit Avatar asked Dec 14 '22 02:12

dirtybit


1 Answers

You can put a try-catch block around every single method call.

Or you take a look at the exception stack trace. Their is described which line of code throwed the exception.

getStackTrace()[0].getMethodName()

EDIT:

Throwable

StackTraceElement

like image 191
Markus Lausberg Avatar answered Feb 15 '23 10:02

Markus Lausberg