IT SOLUTIONS
Your full service technology partner! 
+Expand
   ► KBTo/From GuidesC++  Print This     

Exception Trapping (C++ and C# Cross Reference Guide)

By Mike Prestwood

C++ versus C#: A side by side comparison between C++ and C#.

 
Statements
 

Common statements such as if statements, loops, etc.

Exception Trapping

[Other Languages] 

Languages Focus

A common usage of exception handling is to obtain and use resources in a "try-it" block, deal with any exceptions in an "exceptions" block, and release the resources in some kind of "final" block which executes whether or not any exceptions are trapped.

C++:   try/catch
Syntax Example:
try {
  //Some code.
}
catch(AnError) {
  //Error code here.
}
C#:   try...catch...finally

C# uses a try...catch...finally statement to trap for errors.

try {}
catch {}
finally {}
Syntax Example:
try
{
int y = 0;
y = 1 / y;
}
catch
{
MessageBox.Show("you cannot divide by zero");
}












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]