C#是否有“三元样式”异常处理?

时间:2019-02-18 18:59:34

标签: c# exception-handling conditional-operator

有时我会遇到以下情况:如果一行代码引发了异常,我不在乎异常是什么或为什么抛出该异常;我只需要采取一般措施并继续前进。例如:

        try
        {
            // Throws IndexOutOfRangeException when DB field 
            // is null in the current record
            Template = record.GetString(MYSQL_IDX_TEMPLATE);
        }
        catch
        {
            Template = FIELD_UNAVAILABLE;
        }

我想知道是否有一种基于通用try / catch的简单方法来设置值?

我正在考虑类似于三元语法的东西:

string blah = (index >= ubound ? "No more records" : "records exist");

0 个答案:

没有答案