title: Detect, whether an exception occured when using "ValidatesOnExceptions"
body: <p>Imagine a WPF project with an MVVM approach. So, there is a view and a view model.</p>
  <p>In the view model I have a property, that might throw an exception in the setter.</p>
  <pre><code>Public Property DateValue As Nullable(Of Date)
      Get
          Return _dateValue
      End Get
      Set(value As Nullable(Of Date))
          If value.HasValue Then
              If value.Value &lt; Date.Today Then
                  Throw New Exception(&quot;Error Message&quot;)
              End If
          End If
  
          _dateValue = value
          'skipped NotifyPropertyChanged in this example for the sake of simplicity
      End Set
  End Property
  </code></pre>
  <p>In the view there is a control bound to this property. And since I like to see my exceptions I switched on <code>ValidatesOnExceptions</code> in the binding and add an <code>ErrorTemplate</code>.</p>
  <pre><code>...
  &lt;DatePicker SelectedDate=&quot;{Binding DateValue, ValidatesOnExceptions=True}&quot;
              SelectedDateFormat=&quot;Short&quot;
              Validation.ErrorTemplate=&quot;{StaticResource ErrorTemplate}&quot; /&gt;
  ...
  </code></pre>
  <p>Since you can't reset the value of a <code>DatePicker</code> once you picked one (at least I don't know how to do that) I added a small reset button right next to the <code>DatePicker</code> which is bound to a command which sets the property <code>DateValue</code> of the view model to <code>Nothing</code>. And since I don't want to see this button all the time I bound its <code>Visibility</code> to <code>DateValue.HasValue</code>, so this button only shows, when there's a value to reset.</p>
  <p>So far, so good.</p>
  <p>But now I have a problem when I pick an invalid date in the <code>DatePicker</code> (one that throws an exception in the properties' setter).</p>
  <p>My reset button doesn't show up, since there's no value in the bound property, and I can't reset the <code>DatePicker</code> any other way (at least not that I know of). I'd first have to pick a proper date before I can reset the whole thing.</p>
  <p>So, is there any way to determine, whether my property setter threw an exception. There must be a way, since this very error is shown to the user.</p>
  <p>Or do I have to manually remember, that I threw an exception in another variable, to be able to access this information when needed?</p>
  <p>And how do I &quot;clear&quot; the <code>DatePicker</code>. Since there's no value in the property, setting the property to <code>Nothing</code> will not change anything in the view. How would I get rid of the error?</p>