Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appdomain exception supports #202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions Runtime/BacktraceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1283,6 +1286,35 @@ private void HandleInnerException(BacktraceReport report)
}
}

/// <summary>
/// Handle application domain exception that could happen
/// when the "Script call optimization" option is enabled.
/// </summary>
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<string, string>() {
{ "error.type", BacktraceDefaultClassifierTypes.UnhandledExceptionType }
});
Database.Add(SetupBacktraceData(report));
}


/// <summary>
/// Validate if current client configuration is valid
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion Runtime/Model/BacktraceReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ private void SetClassifierInfo()
}
else
{
Attributes[ErrorTypeAttributeName] = BacktraceDefaultClassifierTypes.ExceptionType;
if (!Attributes.ContainsKey(ErrorTypeAttributeName))
{
Attributes[ErrorTypeAttributeName] = BacktraceDefaultClassifierTypes.ExceptionType;
}
Classifier = Exception.GetType().Name;
}
}
Expand Down