Re: Unhandled exception in class library

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Re: Updating a DB via SQL is giving me a headache
    ... problem will never be executed using the Try/Catch block, ... Connection was certainly created and opened, ... If so, null is not an Integer, and that could throw an exception. ... is handled, execution continues. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: WPF - worker thread causes crash
    ... I left the exception handling out so the code would be easier to read. ... public partial class Window1: Window ... private void btRefresh_Click ... try/catch block, so there's no way for anyone to know what you tried and ...
    (microsoft.public.dotnet.framework)
  • Re: Best Practice?
    ... Even if File.Existsreturns true, the file could disappear before you can actually open it and load it as an XDocument, and you could experience other errors as well." ... If you can do a test that allows you to remove a try/catch block altogether, that's certainly a useful thing to do. ... Every file i/o operation can fail with an exception, and code that doesn't catch the exception is faulty code. ... If you're going to talk about likelihoods, the fact is that having code that has a filename in hand but where a file with that filename actually does not exist is also exceedingly rare. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: try- catch
    ... No. Using the code he proposed, the method that is catching the ... exception returns true or false depending on whether the exception ... intersection with flow-control statements, ... The only thing unusual about a try/catch block as compared to other ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: try/catch block design. Two approaches, which ones best?!
    ... I can either put a try/catch block in every function and have each one ... all this information available to me locally where the exception ... Lead developer of LLBLGen Pro, the productive O/R mapper for .NET ... My .NET blog: http://weblogs.asp.net/fbouma ...
    (microsoft.public.dotnet.languages.csharp)