|
|
|
|
|
by DeathArrow
1341 days ago
|
|
It's not like you can't define your own exceptions in C#, so you always could do what the article is saying. Even if exceptions might be handy, I wouldn't use exceptions for error handling for permance reasons. Instead I have another recommendation: never have void methods and use a Result type that packages the actual value along with an IsValid and Error property. So you will always return Result<T>. That way, error handling is easy and doesn't cause much performance overhead. |
|
Exceptions are slow when thrown.
If an error happens rarely, the corresponding exception is thrown rarely, so the performance impact is minimal.
OTOH, if an error can happen frequently, it is no longer "exceptional", and so is probably better handled without exceptions anyway.