Report handled exceptions
At times, you might expect your app to throws exceptions. When you handle those exceptions with a try-catch block, you can use the Splunk MINT exception handling feature to keep track of any exceptions your app throws and catches. Splunk MINT can also collect customized data associated with an exception.
The Splunk MINT exception handling feature applies only to exceptions your application throws rather than to any app crashes that might occur. Use this to your advantage to create self-explanatory exceptions.
- To log an exception, use the logException(exception) method as follows:
- To add more information to the log, use the logException(key, value, exception) method as follows:
- To specify multiple key-value pairs as a HashMap, use the logException(customdata, exception) method as follows:
try { String a = null; a.toString(); } catch(Exception ex) { // See the stacktrace in your LogCat output ex.printStackTrace(); Mint.logException(ex); }
Mint.logException("level", "second level", ex);
HashMap<String, Object> map = new HashMap<String, Object>(); map.put("level", "second level"); map.put("difficulty", "impossibruuu"); Mint.logException(map, ex);
To view handled exceptions, go to the Errors dashboard in Splunk MINT Management Console, and click Handled under Exception Type in the list of filters.
- Note If you add handling for an exception that was previously displayed in MINT Management Console as a crash, this exception will continue to be displayed as a crash.
The following code examples show different ways to report exceptions.
Example code: Report exceptions
public MyActivity extends Activity { public void dostuff() { try { String a = null; a.toString(); } catch(NullPointerException ex) { // See the stacktrace in your LogCat output ex.printStackTrace(); Mint.logException(ex); } } }
Example code: Report exceptions with custom data
public MyActivity extends Activity { public void dostuff() { try { String a = null; a.toString(); } catch(NullPointerException ex) { ex.printStackTrace(); Mint.logException("level", "second level", ex); // OR: HashMap<String, Object> map = new HashMap<String, Object>(); map.put("level", "second level"); map.put("difficulty", "impossibruuu"); Mint.logException(map, ex); } } }
Example code: Create self-explanatory exceptions
public MyActivity extends Activity { public void getUserProfile() { String userData = getUserDataForID("24"); User user = User.parseData(userData); if (user == null) { Exception ex = new Exception("User profile should not be null"); Mint.logException(ex); } } }
Example code: Log Throwables
public MyActivity extends Activity { public void dostuff() { Throwable tr = new Throwable(); Exception ex = new Exception(tr); Mint.logException(ex); } }
Add and report events | Report ANRs |
This documentation applies to the following versions of Splunk MINT™ SDK for Android (Legacy): 5.2.x
Feedback submitted, thanks!