try { // some code that may throw an exception } catch (Exception e) { Log.e("TAG", Log.getStackTraceString(e)); }
private void foo() { bar(); } private void bar() { baz(); } private void baz() { Log.i("TAG", Log.getStackTraceString(new Throwable())); }This example demonstrates using getStackTraceString method without a throwable object. It creates a new throwable object without any message and logs its stack trace using Log.i method. The android.util.Log class is part of the Android SDK and can be found in the android.util package.