Monday, March 5, 2012

Print current code line number

Do you want to print the line number of the code currently in execution in a Java program. You can use this:

System.out.println ("The line number is " + new Exception().getStackTrace()[0].getLineNumber());

No comments:

Post a Comment