C# Error Handling

Posted on 2014-08-18
Last Modified: 2014-08-25
Any one know how to monitor excat which part of code getting error(without debug),my programme working fine with most of client machine,but some are getting errors , i wrote programme track to what is the error(straigh going to database )

My code
  catch (Exception PageErr)
ErrMessage ="Page Load -"+PageErr.Message.ToString()+"Source -"+ PageErr.Source.ToString() +"StackTrace -"+ PageErr.StackTrace.ToString();

I need to know what is excact place error generating,
Question by:ukerandi
    LVL 35

    Accepted Solution

    It depends if the name method is unique, then that would be enough. For I usually add more info like URL page (You can get that from request and it is handy especially when your URL contains query strings) and any essential data that may help you understand the problem.
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    That information should be in stack trace that you are dumping out. The onus is on you to make sure your code is structured in such a way that you can reliably determine exactly where the error is. A stack trace only shows you the inner-most function that raised the error, not which line caused the error. This is one reason to keep your methods smaller rather than larger. With smaller methods you have less code to look at whenever there is an error.
    LVL 29

    Assisted Solution

    If you mean a line number  - then it is possible if you deploy your code with .pdb files. Code has to be compiled in the Debug mode. Normally no one does that on a number of reasons. Security is one of them.

    Without .pdb files you cannot tell the line number. Also, even line number not always tell you exactly what happened. It depends on how code is written.

    What can I do  is just to advise to follow good practices and write short methods where code does not spread over three - five screens :). Half a screen, at most - one screen. It will be much easier to localize the problem.
    LVL 16

    Assisted Solution

    by:Rose Babu

    by storing full exception details you can find the line number where exactly the exceptions was generated

    catch (Exception PageErr)
        ErrMessage ="Error - "+PageErr.ToString().Replace("'", "");
        // Store the exception in DB for the further error findings

    Open in new window

    Check like this once
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    @Rose Babu

    That is only true if you build and deploy under a Debug configuration, as anarki_jimbel stated. In Release mode, the compiler will optimize your code, and so line numbers will no longer match.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now