|
|
|
|
|
by zvrba
1758 days ago
|
|
> is a tricky situation: would it be really handled incorrectly? Depends. You can't know in a situation like try {
DoA(); DoB();
}
catch (SomethingEx e) { ... }
If previously only DoB could throw SomethingEx and now DoA() can also throw it, the handler is almost certainly incorrect handling if this is some "generic" exception. C#/.NET base library is notorious for using InvalidOperationException for all kinds of unrelated crap.> It's trivial (but tedious) to write code like this Eh. Methods without "throws" would be "unchecked" at runtime as well. So my (imagined) best practice would be that non-private methods declare their exceptions and leave it to the caller whether and how to wrap them. > And in before "don't catch and wrap Exception!" Oh, I do that all the time for precisely the reasons you mentioned. Exceptions from the lowest level are most precise and least useful as there's no information about the context. (Unless you go down the unmaintainable rabbit hole of parsing the call stack.) |
|