• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display line numbers/file name?

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you looking for a solution for debugging and error reporting purposes?
 
Himanshu Jhamb
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic