あなたはどのソリューションを好みますか?私は解決策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;