我有一個控制流問題。在我的公司,我們創建了很多bool
方法,如果出現錯誤,將返回false
。例如:異常與C#中的「if」#
public bool Foo(string path, string fileName, ref string error)
{
if (path == null)
{
error = "path is null";
return false;
}
path += fileName;
return true;
}
正如你可以看到它的醜陋。我想用這樣的例外:
public voidFoo(string path, string fileName, ref string error)
{
if (path == null)
{
throw new SomeException("Path is null.");
}
path += fileName;
return true;
}
但我們擔心的開銷。我們應該嗎?
什麼你真的想要在第二個例子中刪除醜陋的`error`參數。 – 2011-01-23 12:06:13
夥計們,我們真的需要這麼多的答案,說完全一樣的東西嗎? – 2011-01-23 14:13:39