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