Silverlight 4 앱에서 포함 된 컨트롤 (DataGrid)에서 함수를 호출하려고하는데이 함수는 때로는 MS.Internal.WrappedException
의 가짜 예외를 throw합니다. 이 예외는 의미가 없기 때문에 그것을 삼킬 필요가 있습니다. 아쉽게도 예외는 System.Windows.dll에 internal class WrappedException : Exception
으로 선언되어 있으므로 catch
블록에 이름을 지정할 수 없습니다.접근 할 수없는 예외를 처리 할 방법이 있습니까?
질문은이 예외를 감지하고 무시하는 가장 안전한 방법은 무엇입니까? 내가 가지고 올 한 두 가지 옵션은 다음과 같습니다 원래 예외
- 봐 :
ex.GetType().FullName == "MS.Internal.WrappedException"
이 다른 쪽보다 더 나은 방법입니다 : 이름에 대한 ex.InnerException is InvalidOperationException
가 여기에 다양한 옵션을 보여주는 내 함수의 : 관심있는 사람들을 위해
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;
}
}
}
을, 여기에 스택 트레이스의 :
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