Different Types of Errors
You can broadly categorize errors into the following groups:
Syntax errors: These Errors are caused by misspelling words, missing keywords, or otherwise incorrect code.
Logic errors: These Errors in applications run fine but it produce unexpected or unwanted results.
Runtime errors: These Errors cause the application to crash or to behave unexpectedly at run time.
Syntax Errors
Syntax errors are easy to find and fix because they occur during development.In this,the IDE tells you when an error occurs and often prevents you from running the application while it still contains errors. Syntax errors are caused by simple misspelled text, missing or duplicate keywords and characters, and so on.
Here is an example that shows errors that are caught at development time by the compiler. A compile is a program that turns the human-readable code that you write in C# into machine-readable code that can be executed.
C#
mailBody = mailBody.Repalce(“##Name##”, Name.Text); // Replace is misspelled
Response.Write(); // Required parameter for the
// Write method is missing
if (i > 10) // Missing opening brace or
// extraneous closing brace
// Do something here
}
The syntax errors are always displayed in the Error List,which is accessible through the View Tab —> Error List menu.Compiler also give you an up-to-date list of all the syntax errors in your website. To do this, you need to select the Build Tab —> click Build Web Site. Ever if you want to force Visual Studio to recompile the entire site,select Build Tab —-> Click Rebuild Web Site. To go to the location where the error occurred so you can fix it, double-click the error in the Error List. To cycle through the errors and the code where the error occurs, click an error in the Error List and press F8 to go to the next error.
Logic Errors
Logic errors are harder to find because they compile fine but it only occurs during the execution of the code.
Example
C#
string fromAddress = “[email protected]”;
string toAddress = EmailAddress.Text;
myMessage.From = new MailAddress(toAddress);
myMessage.To.Add(new MailAddress(fromAddress));
it is easy to see what the problem is in this example (the To and From addresses are mixed up), but it may be harder to find in a file with 250 lines of code. Additionally, because the compiler will accepts your mistake, you will not be able to notice the error until you see a message in your Inbox that you thought you sent to your users.
The best way to track down and solve logic errors is using the built-in debugging capabilities of Visual Studio.
Runtime Errors
Runtime errors occur at run time, which are difficult to track. Assume you have a site that contains a bug that is hidden somewhere in a page and you have not found it yet, but one of your visitors did and she gets a disagreeable error message.Then What can you do? Probably not much, because there is a fair chance your users will not even inform you about the mistake.
So, it is important to have a good error handling strategy in place that allows you to avoid errors whenever possible.