Interview Question
Qus: Can we create custom exception in dotnet. And How can we create?
Yes we can create a custom exception in .NET.
To create a custom exception, we have two different options -
1. Create the object of a predefined Exception class where we need to pass the error message as a parameter to its constructor and then throw that object so that whenever the exception occurs the given error message gets displayed.
2. Define a new class of type exception and throw that class object by creating it.
Answers (2)
To create a custom exception, we have two different options -
1. Create the object of a predefined Exception class where we need to pass the error message as a parameter to its constructor and then throw that object so that whenever the exception occurs the given error message gets displayed.
2. Define a new class of type exception and throw that class object by creating it.