Guild System.out?

So if I call

public void throwException throws Exception { throw new Exception("foo") ; } 

the output will look something like this:

 java.lang.Exception: foo at SomeClass.throwException(SomeClass.java:5) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ... 

now if i click on (SomeClass.java:5) , the IDE will go to the 5th line in SomeClass.java.

Is it possible to manually create these hyperlinks using System.out or throwing an exception? I already tried to manipulate the Exception by modifying the StackTraceElement, but it seems to work only with valid Java classes.

I am working on a project where I have to parse a uniquely defined file and would like to print hyperlinks that directly lead to the file, instead of the parsing method where the problem occurred.

+4
source share
1 answer

Yes. If you have a class called MyClass, and you want the IDE to provide a link to line 10 of this class, you can do the following:

 System.out.println("(MyClass.java:10)"); 

Note. This post is specifically for the Eclipse IDE; it may be true for others.

EDIT: I just came across this post, maybe it's worth a look: Eclipse Console - what are the rules to track stack traces?

+2
source

Source: https://habr.com/ru/post/1415425/


All Articles