Qus:    Can we create custom exception in dotnet. And How can we create?
Dec 01, 2020 14:59 2 Answers Views: 588 DIVYA

  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.

Prev Next
Answers (2)
PADMAKEECHU Dec 02, 2020 08:27
Answer:   Yes, Custom Exception class is nothing but a user defined class which is derived from System Exception class. Below are the steps, Custom class can be derived from System Exception class. By Creating a constructor of custom class with error message parameter and we can pass it to the base class (System Exception class). Then throw and catch custom exception message in try-catch block in code wherever it is required.

PARTH Dec 03, 2020 08:19
Answer:   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.

Post Your Answer
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect