How to get the source Exception object

I was working on tuning in Java, and I was wondering if it is possible to find out which object threw the exception.

I know that if you make your custom exceptions, you can change the constructor and reference the object:

public class MyEx extends Throwable {
    private MyObject object;

    public MyEx(MyObject o){
        super();
    }

    public MyObject getSource(){
        return object;
    }
}

but I don't know if there is another way to catch who chose the exception. Do you know any other way?

+5
source share
2 answers

If you just want to see from which part of the code an exception is thrown, you have a simple stack trace. You will get this by throwing printStackTrace()exceptions on the instance.

, . , . , , , , . , .

+4
+3

All Articles