java - Is an Exception's stack trace reliable to get calling method name? -


i know stacktraces can used retrieve current executing method this:

thread.currentthread().getstacktrace()[what want] 

however not every jvm provides stack trace way of getting method's name pretty unreliable. anyway...what exceptions? need log caller method name and, in order provide code maintenance, i'd avoid write name down this:

public void mymethod(){   ...  }catch(anexception ex){       log.error("mymethod failed!"); } 

but rather like:

}catch(anexception ex){       log.error("{} failed!", ex.getstacktrace()[0].getmethodname()); //0 should method, caller } 

is reliable? think that, @ least exceptions, jvm should expected provide said stack trace...


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -