Oct 20, 2010 09:40 PM
(This post was last modified: Oct 21, 2010 08:34 AM by Pulser.)
C# Try/Catch
What Is It:
Have you ever been running your application and all of a sudden something goes wrong? Your program crashes and you are left in a daze of confusion and sadness :(.
After setting up a try / catch statement things will work more smoothly. If your compiled application runs into an error, rather than crashing, it will display the error inside of a messageBox.
Getting Started:
So to begin "Trying" to execute code we simply do this:
Code
Try
{
Code Here
}
Catch (System.Exception)
{
MessageBox.Show("There was a super error!");
}The First Line begins trying the code.
The last lines catch the error and display a custom messagebox!
If you want to display the actual error, rather than a custom message, do the following:
Code
{
try
{
Code Here
}
catch (System.Exception error)
{
MessageBox.Show(error.Message);
}
}All your doing is assigning a name and then showing the actual error message!
[IMG]http://i54.[censored].com/2je794x.jpg[/IMG]
Conclusion:
Try / Catch statements can help you out a ton. By using one you prevent program crashes. It makes you look like a more professional coder and it can save everyone a lot of hassle!
http://www.pulsecodes.info
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.
Computer and Information Science major.
Information Technology Apprentice.
Freelance Programmer.


