diff --git a/Runtime/BacktraceClient.cs b/Runtime/BacktraceClient.cs
index 788657b2..1a6a186a 100644
--- a/Runtime/BacktraceClient.cs
+++ b/Runtime/BacktraceClient.cs
@@ -510,6 +510,13 @@ public void Refresh()
#endif
_current = Thread.CurrentThread;
CaptureUnityMessages();
+ if (Configuration.HandleUnhandledExceptions)
+ {
+ AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+#if UNITY_ANDROID || UNITY_IOS
+ Application.lowMemory += HandleLowMemory;
+#endif
+ }
_reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin));
_clientReportAttachments = Configuration.GetAttachmentPaths();
@@ -699,6 +706,7 @@ private void OnDestroy()
_instance = null;
Application.logMessageReceived -= HandleUnityMessage;
Application.logMessageReceivedThreaded -= HandleUnityBackgroundException;
+ AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
#if UNITY_ANDROID || UNITY_IOS
Application.lowMemory -= HandleLowMemory;
#endif
@@ -1014,14 +1022,9 @@ internal void HandleUnhandledExceptionsFromAndroidBackgroundThread(string backgr
private void CaptureUnityMessages()
{
_backtraceLogManager = new BacktraceLogManager(Configuration.NumberOfLogs);
- if (Configuration.HandleUnhandledExceptions)
- {
- Application.logMessageReceived += HandleUnityMessage;
- Application.logMessageReceivedThreaded += HandleUnityBackgroundException;
-#if UNITY_ANDROID || UNITY_IOS
- Application.lowMemory += HandleLowMemory;
-#endif
- }
+ Application.logMessageReceived += HandleUnityMessage;
+ Application.logMessageReceivedThreaded += HandleUnityBackgroundException;
+
}
internal void OnApplicationPause(bool pause)
@@ -1142,7 +1145,7 @@ private bool SamplingShouldSkip()
return value > Configuration.Sampling;
}
- private void SendUnhandledException(BacktraceUnhandledException exception, bool invokeSkipApi = true)
+ private void SendUnhandledException(Exception exception, bool invokeSkipApi = true)
{
if (OnUnhandledApplicationException != null)
{
@@ -1283,6 +1286,35 @@ private void HandleInnerException(BacktraceReport report)
}
}
+ ///
+ /// Handle application domain exception that could happen
+ /// when the "Script call optimization" option is enabled.
+ ///
+ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ {
+ var exception = e.ExceptionObject as Exception;
+ if (OnUnhandledApplicationException != null)
+ {
+ OnUnhandledApplicationException.Invoke(exception);
+ }
+
+ if (ShouldSkipReport(ReportFilterType.UnhandledException, exception, string.Empty))
+ {
+ return;
+ }
+
+ if (Database == null)
+ {
+ SendUnhandledException(exception);
+ return;
+ }
+ var report = new BacktraceReport(exception, new Dictionary() {
+ { "error.type", BacktraceDefaultClassifierTypes.UnhandledExceptionType }
+ });
+ Database.Add(SetupBacktraceData(report));
+ }
+
+
///
/// Validate if current client configuration is valid
///
diff --git a/Runtime/Model/BacktraceReport.cs b/Runtime/Model/BacktraceReport.cs
index 88c3e00e..c2b1b443 100644
--- a/Runtime/Model/BacktraceReport.cs
+++ b/Runtime/Model/BacktraceReport.cs
@@ -188,7 +188,10 @@ private void SetClassifierInfo()
}
else
{
- Attributes[ErrorTypeAttributeName] = BacktraceDefaultClassifierTypes.ExceptionType;
+ if (!Attributes.ContainsKey(ErrorTypeAttributeName))
+ {
+ Attributes[ErrorTypeAttributeName] = BacktraceDefaultClassifierTypes.ExceptionType;
+ }
Classifier = Exception.GetType().Name;
}
}