5

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 jumps to the 5-th line in SomeClass.java.

Is it possible to manually generate those hyperlinks, when using System.out or throwing an Exception? I already tried manipulating an Exception by changing a StackTraceElement, but it seems to work only with valid Java classes.

I'm working on a project, where i have to parse a uniquely defined file and would like to print hyperlinks, which would directly lead to the file, instead of the parse-method where a problem occurred.

Anton Horst
  • 263
  • 1
  • 4
  • 11

1 Answers1

3

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

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

Note: This post specifically refers to Eclipse IDE, it might hold true for others as well.

EDIT: I just came across this post, might be worth a look: Eclipse Console - what are the rules that make stack traces clickable?

Community
  • 1
  • 1
cklab
  • 3,761
  • 20
  • 29
  • Perhaps http://stackoverflow.com/questions/6355286/how-to-format-output-to-console-to-generate-automatic-navigation-hyperlink-fro -- hopefully this one is more helpful :) – cklab May 31 '12 at 17:45
  • well thats something, but still i'm not able to link to other files than Java classes :( – Anton Horst May 31 '12 at 20:38
  • found something [here](http://jimbarritt.com/non-random/2010/05/16/link-from-log-console-output-to-a-line-of-code-in-intellij/), but it still wont work with normal files... – Anton Horst May 31 '12 at 21:24