Jave equivalent of C++ __FUNCTION__ and __LINE__ macros

Here’s one way to get this information, .. add the following line to whatever / wherever you want to trace

System.out.println((new Throwable()).getStackTrace()[0].toString());

Sample output:
com.junk.Junk3.main(Junk3.java:12)

An added advantage of adding debug traces as above is that , when using an IDE such as Eclipse, you can click on an individual trace and automatically beam up the relevant code on your code editor pane.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s