如何获取当前类中方法的名称 [英] how to get the name of method in current class

查看:331
本文介绍了如何获取当前类中方法的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的java类中的Hello
Toto,我有3个静态方法
我想知道当我在其中一个方法中时,如何获取并显示package.class的名称。尝试捕获集团中的方法?
我在methodeA中试过:

Hello in my java class Toto, I have 3 static methods I would like to know when I'm in one of these methods , how to get and display the name of package.class.methode in the try catch bloc ? I tried in methodeA:

public static void methodeA(){

try{
system.out.println("I do something");

}
catch(Exception e){
system.out.println("failed" +e.getClass().getMethods().toString());
}

但它不起作用,我怎样才能在试用中显示它?
谢谢

but it is not working, how also could I show it in try ? thanks

推荐答案

e.printStackTrace(); - 这将打印整个异常stracktrace - 即所有方法+行号。

e.printStackTrace(); - that will print the whole exception stracktrace - i.e. all the methods + line numbers.

这篇关于如何获取当前类中方法的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆