4 ms·
> Why not use ... a plain Exception. It is forbidden. https://learn.microsoft.com/en-us/dotnet/standard/exceptions/#common-exceptions https://learn.microsoft.
by taspeotis 3y ago
> Why not use ... a plain Exception.
It is forbidden.
https://learn.microsoft.com/en-us/dotnet/standard/exceptions/#common-exceptions https://learn.microsoft.com/en-us/dotnet/standard/exceptions...
> Exception ... None (use a derived class of this exception).
https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/using-standard-exception-types https://learn.microsoft.com/en-us/dotnet/standard/design-gui...
> DO NOT throw System.Exception or System.SystemException.
- recursive 3y agoI'm not seeing where it says not to throw InvalidOperationException.
- flowerlad 3y agoIf you want to recover from CSV errors you should ideally throw InvalidCSVException.
- TillE 3y agoInvalidOperationException means "the object is in an inappropriate state". That does not describe a parse error. C# conventions for exceptions are admittedly a bit confusing. There are a handful of very specific scenarios where you're supposed to use a built-in exception (most commonly ArgumentException). For everything else, you want to define your own type.
- recursive 3y agoThe state of the stream, such that it's pointing to an illegal character, actually does seem to be invalid though. Maybe this is an overly pedantic argument. I've been writing quite a bit of c# for over a decade and have basically been doing this the whole time. I thought that I knew how to use exceptions, but it seems I do not.
- throwaway2990 3y agoIt’s a guideline not to. It’s not a hard rule or forbidden.