Re: Unhandled exception in class library
- From: "Cezary Nolewajka" <cezary.nolewajka@xxxxxxxxxxxxx>
- Date: Tue, 22 Jan 2008 11:51:54 +0100
In my understanding you would like to catch all exceptions that might happen, log them, even if you forget try/catch block.
As far as I know, there is no general error handling if an exception is thrown. You need to have a try/catch for that in every routine you expose from your class library.
On top of that, I would mention, that it's generally NOT recommended to handle ALL exceptions. You should handle only those exceptions you KNOW how to handle properly. All other should propagate up the call stack. If you would like to log them, then maybe an idea would be to call them and rethrow after logging.
A nice discussion of exception handling in the above context is here:
http://blogs.msdn.com/fxcop/archive/2006/06/14/FAQ_3A00_-Why-does-FxCop-warn-against-catch_2800_Exception_29003F00_-_2D00_-Part-1-_5B00_Nick-Guerrera_5D00_.aspx
Best regards,
Cezary Nolewajka
Consultant | Microsoft Services | Microsoft | Poland
"raju" <ponnurajs@xxxxxxxxx> wrote in message news:98eab9e3-f4f0-45b9-b4c3-ad50d59979c0@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jan 22, 1:10 pm, "Peter Duniho" <NpOeStPe...@xxxxxxxxxxxxxxxx>
wrote:
On Mon, 21 Jan 2008 23:13:31 -0800, raju <ponnur...@xxxxxxxxx> wrote:
> I am creating one class library in .net. I need to save the
> unhandled exception in a text file. So how to catch the unhandled
> exception from class library.
> Unhandled exception means, i am having try.. Catch block in my
> class library. Even though, if i got the error in any place of my
> code.
I don't understand the question. If you have a try/catch block and you're
catching the exception, doesn't that mean that the exception was handled?
And assuming you've got a try/catch block that's catching the exception,
what's the problem? Can't you use the Exception that's caught for logging
to a text file?
Could you rephrase the question to clarify those issues? It might be
helpful for you to post a little code sample demonstrating the
relationship between the code that throws an exception and how you want to
handle it.
Pete
Hai,
thanks for your immd. reply.
My requirement is, in my "class library", if i forget the
"exception handler" in any one of the place, where we can expect the
exception. That exception should be logged in to a text file, instead
of stop the execution.
eg.,
namespace ECommerce{
public class CardProcessor{
public void MethodCaller(){
CalledMethod();
}
public void CalledMethod(){
throw new Application("Error Raised");
}
}
}
If i used this class library in my project, what will happen? I
am thinking that, it will stop the execution. If my thinking is
correct, then it would not stop the execution, instead of that, the
error will be logged in a text file.
I think, now you will understand my requirement.
Regards,
Raj
.
- References:
- Unhandled exception in class library
- From: raju
- Re: Unhandled exception in class library
- From: Peter Duniho
- Re: Unhandled exception in class library
- From: raju
- Unhandled exception in class library
- Prev by Date: Re: Unhandled exception in class library
- Next by Date: Re: Unhandled exception in class library
- Previous by thread: Re: Unhandled exception in class library
- Next by thread: Re: Unhandled exception in class library
- Index(es):
Relevant Pages
|