First off I run my applications with exceptions thrown on any error (handled or not).
Second I am using a TypeConverter
to convert from a user input string to the actual object.
Third TypeConverter
offers no TryConvert
method so I'm stuck using exceptions for validation, using this rather ugly bit of code here:
try
{
this._newValue = null;
#pragma Magic_SuppressBreakErrorThrown System.Exception
this._newValue = this.Converter.ConvertFromString(this._textBox.Text);
#pragma Magic_ResumeBreakErrorThrown System.Exception
this.HideInvalidNotification();
}
catch (Exception exception)
{
if (exception.InnerException is FormatException)
{
this.ShowInvalidNotification(this._textBox.Text);
}
else
{
throw;
}
}
I'm finding it rather distracting to have VS break execution every-time I type the -
of -1
, or some other invalid character. I could use something similar to this but not all the types I'm converting to have a TryParse
method either.
I'm hoping there may be some way to disable breaking for the section of code within the try
without changing my exception settings.