Chapter 6 Quick Reference


Chapter 6 Quick Reference

To

Do this

Throw an exception

Use a throw statement. For example:

throw new FormatException(source);

Ensure that integer arithmetic is always checked for overflow

Use the checked keyword. For example:

int number = Int32.MaxValue;  checked  {      number++;  }

Catch a specific exception

Write a catch handler that catches the specific exception class. For example:

try  {      ...  }  catch (FormatException fEx)  {      ...  }

Catch all exceptions in a single catch handler

Write a catch handler that catches Exception. For example:

try  {      ...  }  catch (Exception ex)  {      ...  }

Ensure that some code will always be run, even if an exception is thrown

Write the code inside a finally block. For example:

try  {      ...  }  finally  {      // always run  }




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net