|
| ||||||||||
| Tags: custom exception, net application, windows |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to throw a custom exception in .NET?
|
|
#2
| |||
| |||
| Re: How to throw a custom exception in .NET?
The absolute minimum a new custom exception class needs to have is a name. you need to create a custom exception which is thrown if a login attempt fails. A good name for such an exception would be LoginFailedException. Instead of using the preset exceptions from the System.Exception, you define your OwnException class and inherit Exception or ApplicationException class. |
|
#3
| ||||
| ||||
| Re: How to throw a custom exception in .NET?
Creating your own custom exceptions is very easy and allows your code to be more explicit as well as being able to provide more user-friendly error messages. You need to define three constructors in your OwnException Class: One without parameters, other with String parameter for error message and the last one has to have one parameter as a String and other as an Inner exception object. class OwnException : ApplicationException { public OwnException() : base() {} public OwnException(string s) : base(s) {} public OwnException(string s, Exception ae) : base(s, ae) {} } |
|
#4
| |||
| |||
| Re: How to throw a custom exception in .NET?
Structured exception handling was introduced to Visual Basic programmers with the first .NET version of the language. Exception handling semantics in .NET are based on type, so you can create custom exceptions that have their own properties and methods. In .NET, exceptions are first-class citizens, and since they're the built-in error handling mechanism, all .NET-compliant languages must support exceptions. Usually the exceptions that occur in the try are caught in the catch block. The finally is used to do all the cleaning up work. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to throw a custom exception in .NET?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to create a Custom Capsule that is a Custom Firmware with root on lacie 2big Network drive | Kane89 | Networking & Security | 8 | 06-05-2012 12:21 PM |
| No New HD channels ,Should I throw my Tata Sky DTH? | DIMINUTIVE! | India BroadBand | 3 | 18-11-2011 09:32 PM |
| Can someone please tell me what i can throw out in treasure Isle | %Achan | Video Games | 4 | 23-02-2011 04:41 AM |
| How to Throw Exceptions in Java? | Bigga Lexx | Software Development | 4 | 18-02-2010 04:57 AM |
| Difference between throw and throws in Java Exception Handling | KALYAN23 | Software Development | 3 | 09-11-2009 10:49 PM |