你更喜欢什么解决方案?我更喜欢解决方案2,但我想知道是否存在更好的做法谢谢大家
解决方案 1 - try/catch 嵌套
try
{
//some code that could throws Exception1
try
{
//some code that could throws Exception2
return success;
}
catch (Exception2 e)
{
return failure;
}
}
catch (Exception1 e)
{
return failure;
}
解决方案 2 - 尝试/捕获顺序
try
{
//some code that could throws Exception1
}
catch (Exception1 e)
{
return failure;
}
try
{
//some code that could throws Exception2
}
catch (Exception2 e)
{
return failure;
}
return success;