Reputation: 51
https://learn.microsoft.com/en-us/dotnet/api/system.applicationexception?view=net-5.0 says that "ApplicationException Class" Serves as the base class for application-defined exceptions. But in an example at https://learn.microsoft.com/en-us/dotnet/standard/exceptions/how-to-create-user-defined-exceptions custom exception class derives from "Exception" base class.
Upvotes: 2
Views: 528
Reputation: 186678
Well, MSDN states clearly
Important
You should derive custom exceptions from the
Exception
class rather than theApplicationException
class. You should not throw anApplicationException
exception in your code, and you should not catch anApplicationException
exception unless you intend to re-throw the original exception.
So for custom exception we should use Exception
as a base class
Upvotes: 1
Reputation: 8007
Fundamentally, it doesn't matter. If your exception type would be a better logical fit when derived from one of the system-provided exceptions, as a user I'd prefer that kind of implementation. Think about what happens when user of your code catches the exceptions, and plan accordingly.
Upvotes: 0