The the
StackTraceElement
that you can get out of the exception holds this information, like in this example:
package my.company;
public class Program {
public void foo(boolean a) throws Exception{
bar(a);
}
public void bar(boolean a) throws Exception {
if (a)
throw new Exception("I was told to throw!");
}
public static void main(String[] args) {
try {
Program p = new Program();
p.foo(true);
}
catch(Exception e) {
System.out.println("Error caught:");
System.out.println("\t" + e.getMessage());
System.out.println("\tThrown in file " + e.getStackTrace()[0].getFileName());
System.out.println("\tThrown on line " + e.getStackTrace()[0].getLineNumber());
}
}
}
Hope this helps,
Fredrik