Gets the current run code class name, line number, method name in Java

Source: Internet
Author: User
Tags throwable

  Recent items online A bug that reported that the encryption control was entered as empty, because the ios,android,web side is reported, But did not find the reason, because it is even now, so in order to catch this problem, we have to send the error message to the backstage, so write a method to obtain.  
1. Get method Name:
public static String Getcurrentmethodname () {
int level = 1;
stacktraceelement[] Stacks = new throwable (). Getstacktrace () String MethodName = Stacks[level].getmethodname () return methodname}
2. Get the class name:
 public static String getcurrentclassname () {
Span style= "COLOR: #cc7832" >int level = 1 stacktraceelement[] Stacks = new throwable (). Getstacktrace () String ClassName = Stacks[level].getclassname () return classname}


3. Get line number:
 public static int getlinenumber () {
int level = 1 stacktraceelement[] Stacks = new throwable (). Getstacktrace () int linenumber = Stacks[level].getlinenumber () return linenumber}

Gets the current run code class name, line number, method name in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.