pullareddyS wrote:
it is taking too much time to check from which page and for which parameters the error is produced…
Your idea to use
System.Exception.StackTrace
(is that what you use) is actually good enough. You can improve tracing if, instead of using this property, which is just a string, you perform tracing by your own code using the class
System.Diagnostics.StackTrace
:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx[
^].
For example, you can progammatically analyze the stack without pointless string parsing and, say, extract only relevant information which you really want to put in your log and skip all those validation-related steps you mentioned in your question.
Also, you should not be afraid of "taking too much time". Exception, in a reasonably written code, happens rarely. And even when you use exception for handling, say, user input errors (instead of sanitizing of input, which I argued against in my comment to Solution 2, please see), it does not happen often, not more often then the user types. :-) And you can locally handle those exceptions effectively removing then from your general handling with logging. So, whatever you do, the time wasted cannot be anything significant.
Of course, you should avoid the very common fallacy of many beginners: handling exceptions too locally, which defeats the purpose of the technology. All exceptions should be handled in each thread, but only in very few strategically created points of code, which I usually call the "points of competence", where your code context allows you to handle an exception in a sensible way. In all other methods, you should simply let exceptions propagate. This is the hole point of the technology: not to handle exceptions everywhere. Please see my past answers:
When i run an application an exception is caught how to handle this?[
^],
throw . .then ... rethrowing[
^],
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error:...[
^],
Handling exceptions in class library (dll)[
^],
Catching an Exception[
^],
Error Logging and Screen Shot.[
^],
Keep a c# windows form application running despite any unhandled exception[
^],
How do i make a loop that will stop when a scrollbar reaches the bottom[
^].
(Sorry, many points are repeated. This is just what I have in my records. Hope you will see my points anyway; it's not too much reading. :-))
—SA