2017-01-18 7 views
1

未処理の例外が使用されており、Application.Current.DispatcherUnhandledExceptionAppDomain.CurrentDomain.UnhandledException の両方を登録しますが、未処理の例外ハンドラはトリガされません。 未処理の例外はハンドラによってキャッチされません

私は、いくつかのハンドラがトリガされますUIまたはタスクから例外を投げるが、私は

DispatcherUnhandledException

を呼び出すディスパッチャを期待する、以下のようにハンドラが私のシナリオでトリガされていない理由を私は理解していない文書を形成

これはVS 2015と.net 4.5.2

Repro WPFコードは非常に単純で、AllowDropDropハンドラだけです。注:ハンドラーはウィンドウctorに登録されていますが、app.xaml.cs.

&をファイルにドラッグするだけで、メッセージボックスは表示されますが、表示されません。

<Window x:Class="unhandledex_wpf.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525" AllowDrop="True" Drop="MainWindow_OnDrop"> 
    <Grid> 

    </Grid> 
</Window> 

の背後にあるコード:

using System;using System.Threading.Tasks;using System.Windows; 

namespace unhandledex_wpf 
{ 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      Application.Current.DispatcherUnhandledException += (sender, args) => MessageBox.Show("Exception"); 
      AppDomain.CurrentDomain.UnhandledException += (sender, args) => MessageBox.Show("Exception"); 
      TaskScheduler.UnobservedTaskException += (sender, args) => MessageBox.Show("Exception"); 

      // works Task.Run(()=> { throw new Exception("foo"); }); 
     } 

     private void MainWindow_OnDrop(object sender, DragEventArgs e) 
     { 
      throw new NotImplementedException("Catch me"); 
     } 
    } 
} 

答えて

1

ドロップイベント中に例外を処理したい場合は、あなたのDropイベントハンドラ内でそれを処理しなければなりません。 https://social.msdn.microsoft.com/Forums/vstudio/en-US/a336acc8-5a29-45aa-b84a-8e235a0f838a/wpf-drop-event-hides-thrown-error?forum=wpf

:WPFフォーラムでこれを確認した https://social.msdn.microsoft.com/Forums/windows/en-US/8beb1aba-1699-46c7-84dc-38768c7a21f6/treeview-dragdrop-event-ignores-exceptions-help?forum=winforms

ジェイ・ワン(MSFT):理由の詳細については、MSDNフォーラム上で次のスレッドでピーター・リッチーの回答を参照してください

関連する問題