Skip to content

Unexpected exception handling

Stefano Brusadelli edited this page Sep 24, 2020 · 6 revisions

Since v1.4.5 unexpected errors are caught gracefully to prevent unwanted crashes on integrating apps and allow them to keep running without interruptions.

Unexpected error occurrence scenarios

  • When an unexpected error occurs during a call or a chat, this exception will be sent to any registered call and chat observers.
  • If the unexpected error occurs outside a call or a chat, those errors will be delivered to the related sdk module or client observers.
  • The unexpected exception will be also delivered in broadcast and can be retrieved via a broadcast receiver. This is useful for logging purposes and debugging.

Please help us by sending the complete log in such cases to let the issue be fixed as soon as possible. We recommend to create an issue on this repo directly.


How to catch unexpected errors

Register the broadcast receiver in AndroidManifest.xml as shown below:

 <!-- Bandyer unhandled broadcast receiver -->

<application>

        <receiver
            android:name=".exceptions.BandyerExceptionReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.bandyer.android_sdk.BANDYER_UNHANDLED_EXCEPTION" />
            </intent-filter>
        </receiver>

</application>

Add this class in your project:

/**
 * Broadcast Receiver to be used to receive unexpected exceptions' stacktrace from Bandyer SDK.
 */
public class BandyerExceptionReceiver extends BandyerUnhandledExceptionBroadcastReceiver {

    static final String TAG = "BANDYER SDK EXCEPTION";

    @Override
    public void onException(@NonNull Throwable error) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        error.printStackTrace(printWriter);

        Log.e(TAG, stringWriter.toString());
    }
}
Clone this wiki locally