Exceptions are objects. They come from classes that derive from a runtime class called System.Exception. To catch a specific exception in your code you must know the class name of the exception or know the name of one of its parents ( System.Exception is a parent class to all exceptions). For example, a developer may define a general exception like AccountExceptions . Then the developer may define more specific exceptions like InsufficientFundsException and WrongAccountTypeException that derive from AccountExceptions . As someone writing exception-handling code, you can decide to catch a specific exception like InsufficientFundsException , or you can choose to catch all exceptions of the parent type: AccountExceptions . Since all exceptions derive from System.Exception, you can also decide to catch all exceptions, even ones that have nothing to do with Accounts, by writing a catch block that catches System.Exception. To catch a specific exception:
Tips
|