What is the difference between System.Exception vs System.SystemException
In general System exceptions occurred whenever some non-recoverable or fatal error is encountered, like a database crash, bound errors etc. While in case of Application level exceptions some error which is recoverable is encountered, for instance, the wrong type of input data, arithmetic exceptions etc.
SystemException is thrown by the common language runtime when errors occur that are nonfatal and recoverable by user programs. These errors result from failed runtime check (such as an array out-of-bound error), and can occur during the execution of any method.
The SystemException is a predefined exception class in C#. It is used to handle system related exceptions. It works as base class for system exception namespace. It has various child classes like: ValidationException, ArgumentException, ArithmeticException, DataException, StackOverflowException etc.
The SystemException is thrown by the transaction manager to indicate that it has encountered an unexpected error condition that prevents future transaction services from proceeding.
A SystemException is usually reserved for the .NET runtime/framework to use, and not your application code. Basically, don't derive from SystemException when creating your own custom Exception class.
If you are creating your own Exception classes, you should either derive them from Exception or ApplicationException. ApplicationException was originally intended to be used for non-framework exceptions, but it has sort of fallen to the wayside. I believe the framework authors now recommend to derive your custom Exceptions from the base Exception class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With