• English日本語한국어
  • Log inStart now

recordHandledException (Android SDK API)


NewRelic.recordHandledException(Exception $exceptionToHandle)
NewRelic.recordHandledException(Exception $exceptionToHandle, Map of String, Object $exceptionAttributes)
NewRelic.recordHandledException(Throwable $throwableToHandle)
NewRelic.recordHandledException(Throwable $throwableToHandle, Map of String, Object $exceptionAttributes)

Records a handled exception or other throwable type. Optionally takes map with additional attributes showing context.


Agent version 5.15.0 or higher.


Use recordHandledException() within a try{...} catch(){...} block to help understand how often your application is throwing exceptions, and under what conditions.

  1. Import the New Relic SDK API for Android:

    import com.newrelic.agent.android.NewRelic;
  2. Record an exception in your app code, and optionally pass in a map of contextual attributes:

    NewRelic.recordHandledException(Exception $exceptionToHandle, Map of String, Object $exceptionAttributes);

In addition to associated custom attributes, the events will also have associated session attributes. You can view event data in the mobile monitoring UI in the Crash event trail, or via NRQL.

For general information on using the New Relic Android SDK API, see the usage guide.






Required. The exception object that was thrown.


Map of String,Object

Optional. Map of attributes that give context.

Return values

Returns true if the handled exception was recorded successfully, or false if not.


Record handled exception on button press

An example of recording a ClassCastException from within an on-click listener:

public class MainActivity extends Activity {
coolButton.setOnClickListener(new View.OnClickListener() {
Map myMap = new HashMap<>();
public void onClick(View view) {
try {
myMap.put("Key", "Value");
Integer stringVar = (Integer) myMap.get("Key"); //throws ClassCastException
} catch (Exception e) {
NewRelic.recordHandledException(e, myMap);
Copyright © 2023 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.