I work on a WPF application and face with the following issue: When someone who uses our application encounters an exception, we log it to our DB, including the stack trace of the exception. I've encountered an exception with the following stack trace:
System.ArgumentOutOfRangeException: index and length must refer to a location within the string.
Parameter Name: length
at- System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at- Telerik.Windows.Controls.MilitaryDateParser.TryParseSingleDigitDatePart(DateTime& result, DateTime current, String datePart, DayMonthYearIndecesInfo dateIndeces)
at- Telerik.Windows.Controls.MilitaryDateParser.TryParse(String value, DateTime& result, DateTime current)
at- Telerik.Windows.Controls.CompositeDateTimeParser.TryParse(String value, DateTime& result, DateTime current)
at- Telerik.Windows.Controls.RadDateTimePicker.ParseDateTime(String text, IDateTimeParser parser, Nullable`1& dateTime)
at- Telerik.Windows.Controls.RadDateTimePicker.OnDateTimeTextChanged()
at- System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at- System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at- System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at- System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at- System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at- System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at- System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at- System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at- System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at- System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at- System.Windows.Input.InputManager.ProcessStagingArea()
at- System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at- System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
at- System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
at- System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
at- System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at- System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at- MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
The stack trace does not include anything that apply to a line from my application. I understand that something goes wrong with the input given to RadDateTimePicker and it's parsing during OnDateTimeTextChanged().
I want to find out what is the input that fails and also log it, so that next time something goes wrong, I will know the cause.How can I catch the exception, log the input and of course rethrow it?
Basically, in my code, I wrap the RadDateTimePicker with my own control, and bind to its DateTimeTextProperty:
BindingOperations.SetBinding(_radDateTimePicker, RadDateTimePicker.DateTimeTextProperty,
new Binding("DateTimeText")
{
Source = this,
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
I can listen to _radDateTimePicker events, for example: _radDateTimePicker.ParseDateTimeValue += OnRadDateTimePickerParseDateTimeValue;
Any suggestions, Please?
I just want to know the input the causes the error, and do something like that in the correct location in code:Try
{
}
Catch (ArgumentOutOfRangeException ex)
{
Throw new ArgumentException(String.Format("The input was {0}", input), ex)
}
Maybe I should put this code within some event of _radDateTimePicker that I listen to.Thanks!
System.ArgumentOutOfRangeException: index and length must refer to a location within the string.
Parameter Name: length
at- System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at- Telerik.Windows.Controls.MilitaryDateParser.TryParseSingleDigitDatePart(DateTime& result, DateTime current, String datePart, DayMonthYearIndecesInfo dateIndeces)
at- Telerik.Windows.Controls.MilitaryDateParser.TryParse(String value, DateTime& result, DateTime current)
at- Telerik.Windows.Controls.CompositeDateTimeParser.TryParse(String value, DateTime& result, DateTime current)
at- Telerik.Windows.Controls.RadDateTimePicker.ParseDateTime(String text, IDateTimeParser parser, Nullable`1& dateTime)
at- Telerik.Windows.Controls.RadDateTimePicker.OnDateTimeTextChanged()
at- System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at- System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at- System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at- System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at- System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at- System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at- System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at- System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at- System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at- System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at- System.Windows.Input.InputManager.ProcessStagingArea()
at- System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at- System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
at- System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
at- System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
at- System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at- System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at- MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
The stack trace does not include anything that apply to a line from my application. I understand that something goes wrong with the input given to RadDateTimePicker and it's parsing during OnDateTimeTextChanged().
I want to find out what is the input that fails and also log it, so that next time something goes wrong, I will know the cause.How can I catch the exception, log the input and of course rethrow it?
Basically, in my code, I wrap the RadDateTimePicker with my own control, and bind to its DateTimeTextProperty:
BindingOperations.SetBinding(_radDateTimePicker, RadDateTimePicker.DateTimeTextProperty,
new Binding("DateTimeText")
{
Source = this,
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
I can listen to _radDateTimePicker events, for example: _radDateTimePicker.ParseDateTimeValue += OnRadDateTimePickerParseDateTimeValue;
Any suggestions, Please?
I just want to know the input the causes the error, and do something like that in the correct location in code:Try
{
}
Catch (ArgumentOutOfRangeException ex)
{
Throw new ArgumentException(String.Format("The input was {0}", input), ex)
}
Maybe I should put this code within some event of _radDateTimePicker that I listen to.Thanks!