To effectively deal with errors and error messages CSharp .Net give you the ability to use the try and catch methods.
The Try and Catch Methods
Using the try and catch method you easily retrieve detailed information about the error, display personally customized error messages, or ignore the error completely and move on to the next section of code.
Below is an example use of the try and catch method of error handling:
try
{
//Because the File is not there an error will be trigger or raised.
System.Diagnostics.Process.Start("c:\\this\\file\\isnt\\here.exe");
}
catch (Exception myerror)
{
//Tell the user there was an error and show the error's description
MessageBox.Show("There was an error: " + myerror.Message);
}
This will code will attempt to start an executable file that does not exist, thus raising an error event. When the error is encountered the catch method is addressed showing a message box that will display a description of the error.
To ignore the error simply replace the catch method like this:
try
{
//Because the File is not there an error will be trigger or raised.
System.Diagnostics.Process.Start("c:\\this\\file\\isnt\\here.exe");
}
catch {}
To get a description or detail information about the error that was raised simply read the string myerror.Message. By reading the error's description or message text you can differentiate between different error, hence giving you the ability to execute different code for different errors.
Conclusion
Now you can easily customize the way your application handles each error giving a personal response, using the CSharp .Net framework's try and catch error handling method.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
"Setup Cannot Copy the File Staxmem.Dll" Error MessageSteps on how to get around the error "Setup cannot copy the file staxmem.dll" error message when you try to install IIS on a computer that is running Windows XP Pro.- Troubleshooting the "Autochk Program Not Found" ErrorThe "Autochk Program Not Found" error occurs when you try to uninstall Norton Antivirus. The Norton GoBack tool attaches itself to the hard drive and it will hide your partition when it uninstalls. You can easily solv...
- Troubleshooting the Windows "Limited or No Connectivity" Error Sometimes you may get the error message "This connection has limited or no connectivity. You might not be able to access the Internet or some network resources." Here's how to fix it:
- Human Error and What to DoHuman error is something we have to accept as part of life. Here are ten ways human error may have affected or will affect you, and what you can do to help avoid it!
GPS User Errors and How to Avoid Them: The Dreaded Data Input ErrorThe most consistent source of gps error is the user. The errors usually result from incorrectly reading latitude and longitude coordinates from a chart or map.
- Common Secondary Language Learning Errors
- Errors in World Series History
- The Difference Between Type I and Type II Common Thinking Errors
- Need Some Comforting? Try Out Some of These Orange County Restaurants
- Photoshop Tutorial: Changing the Color Tone of Your Photos
- Try New Poetry for National Poetry Month
- Real Estate Specializing: Triple Net Lease Property



