Learn how to a build a cloud-first strategyRegister Now


C# Error Handling

Posted on 2014-08-18
Medium Priority
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 36

Accepted Solution

Miguel Oz earned 400 total points
ID: 40269127
It depends if the name method is unique, then that would be enough. For asp.net 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 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 800 total points
ID: 40269255
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 30

Assisted Solution

anarki_jimbel earned 400 total points
ID: 40269260
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
Rose Babu earned 400 total points
ID: 40269841

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 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 800 total points
ID: 40270108
@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.

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

810 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