C # pragma to suppress error break

Firstly, I launch my applications with exceptions that have occurred with any error (processed or not).

Secondly, I use TypeConverterto convert from user input string to the actual object.

The third one TypeConverterdoes not offer a method TryConvert, so I am stuck using exceptions to check 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 find it rather distracting to interrupt the execution of the VS interrupt every time, I type -of -1or some other invalid character. I could use something similar to this , but not all types that I convert have a method TryParse.

, - try .

+3
4

, , VS , , "" (ctrl-alt-e). Common Language Runtime Exceptions . FormatException . , VS , FormatException.

+1

try/catch :

[System.Diagnostics.DebuggerNonUserCode]

( ). , , .

+13

" → " .

+1

, , , TypeConverter, ( "DEBUG" ) - TypeConverter ( ), TypeConverter.

, - , , .

0

Source: https://habr.com/ru/post/1738442/


All Articles