diff --git a/DesktopClock.Tests/ColorTextConverterTests.cs b/DesktopClock.Tests/ColorTextConverterTests.cs index 49aef65..dbfbb38 100644 --- a/DesktopClock.Tests/ColorTextConverterTests.cs +++ b/DesktopClock.Tests/ColorTextConverterTests.cs @@ -48,6 +48,9 @@ public void Convert_ShowsAColorPickedElsewhereInFull() [InlineData("#FF000")] [InlineData("#GG0000")] [InlineData("Reddish")] + [InlineData("sc#")] + [InlineData("sc#1e999,0,0")] + [InlineData("ContextColor foo 1,2,3")] public void ConvertBack_RejectsUnreadableText(string text) { Assert.Equal(DependencyProperty.UnsetValue, new ColorTextConverter().ConvertBack(text, typeof(Color), null, Culture)); diff --git a/DesktopClock/Utilities/ColorTextConverter.cs b/DesktopClock/Utilities/ColorTextConverter.cs index c03d136..e69dadc 100644 --- a/DesktopClock/Utilities/ColorTextConverter.cs +++ b/DesktopClock/Utilities/ColorTextConverter.cs @@ -35,9 +35,9 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu _typedText = text; return _typedColor; } - catch (FormatException) + catch (Exception) { - // Unreadable text, like a half-typed color, leaves the color as it was and marks the box invalid. + // Unreadable text, like a half-typed color, leaves the color as it was and marks the box invalid. The error isn't always a FormatException: "sc#" gives an InvalidOperationException, and WPF doesn't catch what a converter throws. return DependencyProperty.UnsetValue; } }