|
14 | 14 | using System.Windows.Media; |
15 | 15 | using System.Windows.Threading; |
16 | 16 | using Dynamo.Configuration; |
| 17 | +using Dynamo.Core; |
17 | 18 | using Dynamo.Engine; |
18 | 19 | using Dynamo.Exceptions; |
19 | 20 | using Dynamo.Graph; |
|
22 | 23 | using Dynamo.Graph.Nodes; |
23 | 24 | using Dynamo.Graph.Workspaces; |
24 | 25 | using Dynamo.Interfaces; |
| 26 | +using Dynamo.Logging; |
25 | 27 | using Dynamo.Models; |
26 | 28 | using Dynamo.PackageManager; |
27 | 29 | using Dynamo.PackageManager.UI; |
|
30 | 32 | using Dynamo.Services; |
31 | 33 | using Dynamo.UI; |
32 | 34 | using Dynamo.UI.Prompts; |
33 | | -using Dynamo.Updates; |
34 | 35 | using Dynamo.Utilities; |
35 | 36 | using Dynamo.Visualization; |
36 | 37 | using Dynamo.Wpf.Interfaces; |
@@ -675,6 +676,8 @@ public struct StartConfiguration |
675 | 676 |
|
676 | 677 | protected DynamoViewModel(StartConfiguration startConfiguration) |
677 | 678 | { |
| 679 | + Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException; |
| 680 | + |
678 | 681 | this.ShowLogin = startConfiguration.ShowLogin; |
679 | 682 |
|
680 | 683 | // initialize core data structures |
@@ -754,6 +757,33 @@ protected DynamoViewModel(StartConfiguration startConfiguration) |
754 | 757 | FileTrustViewModel = new FileTrustWarningViewModel(); |
755 | 758 | } |
756 | 759 |
|
| 760 | + private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) |
| 761 | + { |
| 762 | + if (e.Handled) |
| 763 | + { |
| 764 | + return; |
| 765 | + } |
| 766 | + |
| 767 | + e.Handled = true; |
| 768 | + CrashGracefully(e.Exception); |
| 769 | + } |
| 770 | + |
| 771 | + private void CrashGracefully(Exception ex) |
| 772 | + { |
| 773 | + try |
| 774 | + { |
| 775 | + Model?.Logger?.LogError($"Unhandled exception {ex.Message}"); |
| 776 | + |
| 777 | + DynamoModel.IsCrashing = true; |
| 778 | + Analytics.TrackException(ex, true); |
| 779 | + Model?.OnRequestsCrashPrompt(new CrashErrorReportArgs(ex)); |
| 780 | + |
| 781 | + Exit(false); // don't allow cancellation |
| 782 | + } |
| 783 | + catch |
| 784 | + { } |
| 785 | + } |
| 786 | + |
757 | 787 | /// <summary> |
758 | 788 | /// Sets up the provided <see cref="DefaultWatch3DViewModel"/> object and |
759 | 789 | /// adds it to the Watch3DViewModels collection. |
@@ -3412,6 +3442,8 @@ public ShutdownParams( |
3412 | 3442 | /// |
3413 | 3443 | public bool PerformShutdownSequence(ShutdownParams shutdownParams) |
3414 | 3444 | { |
| 3445 | + Dispatcher.CurrentDispatcher.UnhandledException -= CurrentDispatcher_UnhandledException; |
| 3446 | + |
3415 | 3447 | if (shutdownSequenceInitiated) |
3416 | 3448 | { |
3417 | 3449 | // There was a prior call to shutdown. This could happen for example |
|
0 commit comments