![]() |
| | #1 |
| Registered User Join Date: Oct 2005
Posts: 3
| Handling Exceptions public xxxxexception class \\declare variables public string name public int number \\constructor public xxxxexception (string name,int number) \\try \\catch \\finally I'm really confused |
| augie0216 is offline | |
| | #2 |
| Anti-Poster Join Date: Feb 2002
Posts: 1,229
| You've got several options. You could certainly create an exception class for each kind of exception you want to throw. You could create an exception class that held an enumeration that you could check to see what was thrown (I wouldn't, though; it's easier to catch derived classes of exceptions). You could create a generic exception class for catching any exception thrown by a specific class. It really depends on what you need to do. If you're planning on using exceptions, you should decide which of the above best fits your needs. For example, is it more important for you to catch all exceptions generated by one class or to catch one kind of exception generated by any class? It's two different kinds of hierarchy that can't be easily merged. In general, all you need to do to create an exception class is derive from either Exception or ApplicationException and provide a few constructors. For example: Code: using System.Runtime.Serialization;
[Serializable]
public class UserException : ApplicationException
{
public UserException()
{
}
public UserException(string message)
: base(message)
{
}
public UserException(string message, Exception innerException)
: base(message, innerException)
{
}
public UserException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Code: [Serializable] public class UserException<T> : UserException Code: [Serializable] public class MathException : UserException Attached is a sample code file showing exception classes and handling of exceptions.
__________________ Rule #1: Every rule has exceptions |
| pianorain is offline | |
| | #3 |
| Registered User Join Date: Oct 2005
Posts: 3
| Thanks for the help |
| augie0216 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| signal handling and exception handling | lehe | C++ Programming | 2 | 06-15-2009 10:01 PM |
| event handling is serialized in MS Visual Studio C++ 2005 ?? | mynickmynick | Windows Programming | 3 | 08-07-2008 04:47 AM |
| Exception handling framework based on multiple inheritance | Mario F. | C++ Programming | 11 | 06-25-2007 10:17 AM |
| Handling Global Project Wide Exceptions | doom | C# Programming | 0 | 09-12-2005 10:17 AM |