nikhil deshpande
nikhil deshpande

Reputation: 41

How to print Line numbers as and when java code is executed

H All, I want to trace which lines are executed in my code so that I can highlight those lines. Due to this i am able to trace the code which is not tested.

i found out that JDB is way through which I can actually debug my application but I am not able to connect JDB with my eclipse code which is running. So in good scenario what I want is my code is running on eclipse and I am connected to that code via JDB and able to get all the line numbers which are executred

Upvotes: 3

Views: 1353

Answers (2)

Sintrias
Sintrias

Reputation: 586

This will get you the line number in the file that the stack trace code is called in:

Thread.currentThread().getStackTrace()[1].getLineNumber();

This will get you the line number in the file where the method that contains the stack trace code is called:

Thread.currentThread().getStackTrace()[2].getLineNumber();

Upvotes: 2

ABLX
ABLX

Reputation: 736

I think Eclipse Debugger would do the job, so you can go trough you code line by line

http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/junor

but this is included in nearly any ide

Upvotes: 1

Related Questions