Skip to content

Commit

Permalink
feat: Add a generic Application.UnhandledException handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 13, 2024
1 parent cb5ac18 commit f35388c
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ private void BuildApplicationInitializerBody(IndentedStringBuilder writer, XamlO
}
}

AttachUnhandledExceptionHandler();

void ApplyLiteralProperties()
{
writer.AppendLineIndented("this");
Expand All @@ -563,6 +565,18 @@ void ApplyLiteralProperties()

writer.AppendLineIndented(";");
}

void AttachUnhandledExceptionHandler()
{
writer.AppendLineIndented($"#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION");
writer.AppendLineIndented($"UnhandledException += (s, e) =>");
writer.AppendLineIndented("{");
writer.Indent();
writer.AppendLineIndented("if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();");
writer.Indent(-1);
writer.AppendLineIndented("};");
writer.AppendLineIndented($"#endif");
}
}

/// <summary>
Expand Down

0 comments on commit f35388c

Please sign in to comment.