This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to display line numbers/file name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to display line numbers/file name?" Watch "How to display line numbers/file name?" New topic
Author

How to display line numbers/file name?

Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Hi.
For programmers familiar with C programming, we could print out the line numbers and file names by certain flags like __LINE__ and __FILE__ in the code itself.
Is there any way to do such a thing in Java ?
Any help would be appreciated.
thanks
- Himanshu


Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Are you looking for a solution for debugging and error reporting purposes?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Yes, you can say that.
I need to track memory usage at certain points in my code & need to display the exact location of the checkpoints in my code. Hence, the question.
thx.
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
Java API does not provide any direct way to do this but you can make use of printStackTrace() method. Write your debug statement such that it throws a Throwable and then catches it. Customize printStackTrace() to print the third line of the stack Trace. This will give you the class file and line number.
Hope this helps.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display line numbers/file name?
 
Similar Threads
java debugging
Server side debugging problem
Question Frm k&B chp 5 Self test Qno :- 8
empty vector cells
Java Binary file vs Java ASCII File