Re: Custom Exception Handler Class
From: David Levine (noSpamdlevineNNTP2_at_wi.rr.com)
Date: 06/22/04
- Next message: K: "Job Posting: Senior Developer, C++/C#, SQL, ADO.NET"
- Previous message: Henry Chen: "check service pack version"
- In reply to: Trace: "Custom Exception Handler Class"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 21 Jun 2004 19:21:44 -0500
"Trace" <Trace@discussions.microsoft.com> wrote in message
news:9842F6E4-0EF1-46AD-845A-0F6742BFC1D6@microsoft.com...
> I am attempting to develop a custom class wich handles caught exceptions,
much like the ExceptionManager. I am having difficulty in informing the
compiler that my custom class will handle the exception appropriately.
>
> For instance:
>
> bool System.Collections.IDictionary.Contains(object key)
> {
> if(key is string)
> return(this.Contains((string) key));
> else
> throw(new ArgumentException("key must be of type string.", "key"));
> }
>
> The above compiles just fine.
>
> bool System.Collections.IDictionary.Contains(object key)
> {
> if(key is string)
> return(this.Contains((string) key));
> else
> ExceptionHandler.Handle(new ArgumentException("key must be of type
string.", "key"));
> }
>
> The above will not compile due to the fact that the compiler detect sthe
execution path the does not provide a return.
>
> I know I can modify the code to get this to work, but I was wondernig if
anyone knows of an interface or something that my ExceptionHandler can use
to inform the compiler that it will be stopping execution stream and can
therfore compile the above code.
There's no way to tell the compiler to treat a method call like a return
statement, but you can define your method as:
public System.Exception ExceptionHandler.Handle(System.Exception
innerException); // returns an exception object
then you can write:
if(key is string)
return(this.Contains((string) key));
else
throw ExceptionHandler.Handle(new ArgumentException("key must be of
type string.", "key"));
- Next message: K: "Job Posting: Senior Developer, C++/C#, SQL, ADO.NET"
- Previous message: Henry Chen: "check service pack version"
- In reply to: Trace: "Custom Exception Handler Class"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|