Silverlight 4アプリケーションでは、インクルードコントロール(DataGrid)で関数を呼び出していますが、この関数はタイプがMS.Internal.WrappedException
の偽の例外をスローすることがあります。この例外は意味がないので、私はそれを飲み込む必要があります。残念ながら、例外はSystem.Windows.dll内でinternal class WrappedException : Exception
と宣言されているため、catch
ブロックに名前を付けることはできません。アクセスできない例外を処理する方法はありますか?
質問は、この例外を検出して無視する最も安全な方法は何ですか?私が作ってみた2つのオプションがあります。元の例外のための
- ルック:名の
ex.InnerException is InvalidOperationException
- ルック:
ex.GetType().FullName == "MS.Internal.WrappedException"
は一方が他方よりずっといいですか?私が考えなかった別の選択肢がありますか?
はここで異なるオプションを示す私の機能です。興味がある人のために
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedAlarm = alarmList.SelectedItem as Alarm;
if (selectedAlarm != null)
{
dataGrid.SelectedItem = selectedAlarm.Source;
try
{
dataGrid.ScrollIntoView(dataGrid.SelectedItem, null);
}
// catch (MS.Internal.WrappedException ex) doesn't compile
catch (Exception ex)
{
if (ex.InnerException is InvalidOperationException) // 1
if (ex.GetType().FullName == "MS.Internal.WrappedException") // 2
{
// ignore exception
}
else
throw;
}
}
}
を、ここでのStackTraceです:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.Controls.DataGrid.InsertDisplayedElement(Int32 slot, UIElement element, Boolean wasNewlyAdded, Boolean updateSlotInformation) at System.Windows.Controls.DataGrid.InsertDisplayedElement(Int32 slot, Boolean updateSlotInformation) at System.Windows.Controls.DataGrid.GetExactSlotElementHeight(Int32 slot) at System.Windows.Controls.DataGrid.ScrollSlotIntoView(Int32 slot, Boolean scrolledHorizontally) at System.Windows.Controls.DataGrid.ScrollSlotIntoView(Int32 columnIndex, Int32 slot, Boolean forCurrentCellChange, Boolean forceHorizontalScroll) at System.Windows.Controls.DataGrid.ScrollIntoView(Object item, DataGridColumn column) at DtDemo.Home.alarmList_SelectionChanged(Object sender, SelectionChangedEventArgs e)
とここにあるInnerException.StackTrace:
at System.Windows.Controls.DataGridRow.get_ActualDetailsVisibility() at System.Windows.Controls.DataGridRow.OnApplyTemplate() at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
私は 'InternalException'のどの小道具を調べるべきか分かりません。メッセージはローカライズされているため、無用です。私は確かにスタックトレースに依存したくない! – Gabe