Library-wise exception type #624

Closed
opened 2026-01-29 22:14:47 +00:00 by claunia · 4 comments
Owner

Originally created by @fuzzah on GitHub (Apr 16, 2024).

Originally assigned to: @Copilot on GitHub.

Please consider declaring a common exception type for the library (like SharpCompressException) and inheriting all specific exception types from it instead of subclassing base Exception class in different places.
It would improve user experience, as now users need to catch (Exception) which could mask actual errors such as hypothetical NullReferenceException in SharpCompress or exceptions thrown from some unrelated code residing in the same try block.

Originally created by @fuzzah on GitHub (Apr 16, 2024). Originally assigned to: @Copilot on GitHub. Please consider declaring a common exception type for the library (like SharpCompressException) and inheriting all specific exception types from it instead of subclassing base Exception class in different places. It would improve user experience, as now users need to `catch (Exception)` which could mask actual errors such as hypothetical NullReferenceException in SharpCompress or exceptions thrown from some unrelated code residing in the same try block.
claunia added the enhancement label 2026-01-29 22:14:47 +00:00
Author
Owner

@adamhathcock commented on GitHub (Apr 17, 2024):

Sounds good

@adamhathcock commented on GitHub (Apr 17, 2024): Sounds good
Author
Owner

@adamhathcock commented on GitHub (Apr 23, 2024):

Base exception:
SharpCompressException from ApplicationException

Need to see what other exceptions I define as there seem to be some specific ones but mostly using framework ones

@adamhathcock commented on GitHub (Apr 23, 2024): Base exception: `SharpCompressException` from `ApplicationException` Need to see what other exceptions I define as there seem to be some specific ones but mostly using framework ones
Author
Owner

@reima commented on GitHub (Apr 28, 2025):

Please be advised that custom exceptions should be derived from the Exception class, and not from ApplicationException (see remarks at https://learn.microsoft.com/en-us/dotnet/api/system.applicationexception?view=net-9.0).

@reima commented on GitHub (Apr 28, 2025): Please be advised that custom exceptions should be derived from the `Exception` class, and not from `ApplicationException` (see remarks at https://learn.microsoft.com/en-us/dotnet/api/system.applicationexception?view=net-9.0).
Author
Owner

@adamhathcock commented on GitHub (Apr 28, 2025):

You're right. Not sure why I thought it was a good idea.

I also forgot the PR

@adamhathcock commented on GitHub (Apr 28, 2025): You're right. Not sure why I thought it was a good idea. I also forgot the PR
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#624