The Visual Basic .NET Programming Language
< Day Day Up > |
In an ideal world, all programs would execute perfectly and always produce the correct value. In reality, however, bugs and other unexpected situations happen. These situations are dealt with in the .NET Framework through exceptions . An exception is an object that represents an unexpected or exceptional situation. An exception contains information that can be used to help understand what went wrong and where. When an error condition occurs in a program or in the Framework, a new exception object is created and thrown . Throwing an exception causes the program to stop executing and passes control to the .NET Framework, which looks for a specific kind of code, called an exception handler , which can catch the exception and handle it in some specific way.
When an exception is thrown, the .NET Framework starts by looking for an exception handler in the method that threw the exception. If the current method has no handler to catch the exception, the Framework looks at the method that called the method that threw the exception. If that method has no handler, it then looks at the method that called the method that called the method that threw the exception, and so on. Eventually, the Framework reaches the Main method. If the Main method does not catch the exception, the exception is considered "unhandled," and the Framework will terminate the program and inform the user that an unhandled exception has occurred.
|
< Day Day Up > |