Chapter 13. Exception handling


If you are a Java developer, C#'s exception handling mechanism is very similar to Java's, and you will feel very comfortable. [1] There are, of course, new things to learn “ C# has done away with checked exceptions and built in something called inner exceptions, as well as other minor improvements.

[1] VB 6 developers will find exception handling a totally new thing to pick up when they move over to VB .NET. VB 6 has no proper exception handling mechanism, and developers rely on the ancient On Error Goto construct to handle errors.

C# has four keywords for exception handling “ try , catch , finally , and throw . Notice that C# does not have the throws keyword which Java developers use when declaring methods .

I shall start with a general example of exception handling in C# just to warm up a bit. This will be followed by examples on nested try blocks and user -defined exceptions. [2] Then I will discuss the following topics:

[2] User-defined exceptions are exception classes written by the developer.

  • The C# exception class hierarchy;

  • System.Exception class;

  • inner exceptions;

  • general catch block;

  • catching generic exceptions.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

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