java获取异常名字,通过解析异常获取方法名称并包含参数

When I received an exception such as IOException or RunTimeException, I can only know the line number in the class.

First of my question. Is it possible to retrieve the method name through exception?

Second, is it possible to retrieve the method and the parameter of this method by line number?

p.s. I need to know the exact method name and its parameters, because I want to distinguish the overloading methods. To distinguish overloading methods, all that I know is to determine its parameters.

解决方案

try{

//your code here}

catch(Exception e){

for (StackTraceElement st : e.getStackTrace())

{

System.out.println("Class: " + st.getClassName() + " Method : "

+ st.getMethodName() + " line : " + st.getLineNumber());

}

}

as you can see in the code above, you can get the stackTrace and loop over it to get all the method names and line numbers, refer to this for more info http://download.oracle.com/javase/1.4.2/docs/api/java/lang/StackTraceElement.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值