Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-get-example Get Calling Class

Related Tutorials


 
 

Share on Google+Share on Google+

Get Calling Class

Advertisement
In this example we will find the name of the class name. Description of the method used in the example: getStackTrace: Provides programmatic access to the stack trace information printed by printStackTrace().

Get Calling Class

     

In this example we will find the name of the class name.
Description of the method used in the example:
getStackTrace: Provides programmatic access to the stack trace information printed by printStackTrace(). It returns array of StackTraceElement objects.
getClassName: It returns String type fully qualified name of the class containing the execution point represented by this stack trace element.

 

 

Here is the code of GetCollingClass.java

class GetCallingClass 
{
 public static void main(String args[]){
  new GetCallingClass().hello();
 }
 
 void hello()
 {
  try
  {
 throw new Exception("Error");
  }
  catch( Exception e )
  {
 System.out.println( e.getStackTrace()[1].getClassName());
 }
}
}

 

Output will be displayed as:

 

Download Source Code

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2008

Related Tutorials

Discuss: Get Calling Class   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com