重複の可能性:
.NET 例外はどれくらい遅いですか?
例外をスローしてすぐにキャッチするためのオーバーヘッドはありますか? これに違いはありますか
void DoSomething(object basic)
{
try
{
if (basic == null)
throw new NullReferenceException("Any message");
else
{
//...
}
}
catch (Exception error)
{
_logger.WriteLog(error);
}
}
そしてこれ(ここでは例外をスローしません):
void DoSomething(object basic)
{
try
{
if (basic == null)
{
_logger.WriteLog(new NullReferenceException("Any message");
return;
}
else
{
...
}
}
catch (Exception error)
{
_logger.WriteLog(error);
}
}
2 番目のフラグメントは高速になるかどうか。
また、あるソリューションが別のソリューションよりも速い理由を知りたいです。