pangpanghuan
public class Test1 {

    public static void main(String args[]) {
        System.out.println(getLineInfo());
        getExp();
    }

    public static String getLineInfo() {
        StackTraceElement ste = new Throwable().getStackTrace()[1];
        return ste.getFileName() + ": Line " + ste.getLineNumber();
    }

    public static String getExp(){
        try{
            throw new Exception("Exception Test");
        }catch(Exception e){
            StackTraceElement ste =e.getStackTrace()[0];
            System.out.println(ste.getClassName());
            System.out.println(ste.getFileName());
            System.out.println(ste.getLineNumber());
            System.out.println(ste.getMethodName());
        }
        return null;
    }
}

 

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2022-02-04
  • 2021-05-05
  • 2021-10-28
  • 2021-07-01
  • 2022-02-10
  • 2021-09-23
  • 2021-06-26
猜你喜欢
  • 2022-02-11
  • 2022-12-23
  • 2021-11-14
  • 2021-12-17
  • 2021-05-15
  • 2021-08-07
  • 2022-01-05
相关资源
相似解决方案