1 // Copyright 2015-present 650 Industries. All rights reserved.
2 package host.exp.exponent
3 
4 import android.content.Context
5 import host.exp.exponent.analytics.EXL
6 import host.exp.exponent.experience.ExperienceActivity
7 
8 class ExponentUncaughtExceptionHandler(private val context: Context) : Thread.UncaughtExceptionHandler {
9   private val oldExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
10 
uncaughtExceptionnull11   override fun uncaughtException(thread: Thread, ex: Throwable) {
12     try {
13       ExperienceActivity.removeNotification(context)
14     } catch (e: Throwable) {
15       // Don't ever want to crash before getting to default exception handler
16       EXL.e(TAG, e)
17     }
18     oldExceptionHandler.uncaughtException(thread, ex)
19 
20     // TODO: open up home screen with error screen preloaded.
21     // KernelProvider.getInstance().handleError doesn't always work because sometimes the process gets corrupted.
22     System.exit(1)
23   }
24 
25   companion object {
26     private val TAG = ExponentUncaughtExceptionHandler::class.java.simpleName
27   }
28 }
29