VB.net Tutorials

1. Using Resume Next and Resume Line in VB.net

By: Steven Holzner : 2010-11-17

Description: One of the most useful aspects of unstructured exception handling is the Resume statement, which lets you resume program execution even after an exception has occurred. You can use Resume to resume execution with the statement that caused the exception, Resume Next to resume execution with the statement after the one that caused the exception, and Resume line, where line is a line number or label that specifies where to resume execution. Here's an example using Resume Next, which lets you skip over the line that caused the problem:


2. Using On Error GoTo 0 in VB.net

By: Steven Holzner : 2010-11-17

Description: To turn off unstructured exception handling, you can use the On Error GoTo 0 or On Error GoTo -1 statements. Here's an example:


3. Getting an Exception's Number and Description in VB.net

By: Steven Holzner : 2010-11-17

Description: For more information on exceptions, you can use the Err object's Number and Description properties, like this:


4. Raising an Exception Intentionally in VB.net

By: Steven Holzner : 2010-11-17

Description: There are cases in programs where you might want to create an exception because, although no Visual Basic trappable exception has occurred, some situation may have occurred that's incompatible with your program's logic. You can create an exception intentionally, called raising an exception, with the Visual Basic Err object's Raise method, which is declared this way internally in VB .NET:


5. Exception Filtering in the Catch Block in VB.net

By: Steven Holzner : 2010-11-17

Description: When you're handling exceptions, you usually want to handle different types of exceptions differently, according to the nature of the exception that occurred. This process is called filtering. There are actually two ways to filter exceptions with Catch blocks. First, you can filter on specific classes of exceptions, which means you have to prepare for the various exceptions you want to handle.


6. Using Multiple Catch Statements in VB.net

By: Steven Holzner : 2010-11-17

Description: You also can use multiple Catch statements when you filter exceptions. Here's an example that specifically handles overflow, invalid argument, and argument out of range exceptions:


7. Using Finally in VB.net

By: Steven Holzner : 2010-11-17

Description: The code in the Finally block, if there is one, is always executed in a Try…Catch…Finally statement, even if there was no exception, and even if you execute an Exit Try statement. This allows you to deallocate resources and so on; here's an example with a Finally block:


8. Throwing an Exception in VB.net

By: Steven Holzner : 2010-11-17

Description: You can throw an exception using the Throw statement, and you can also rethrow a caught exception using the Throw statement. Here's an example where I'm explicitly throwing an overflow exception:


9. Throwing a Custom Exception in VB.net

By: Steven Holzner : 2010-11-17

Description: You can customize the exceptions you throw by creating a new exception object based on the ApplicationException object. Here's an example where I'm creating a new ApplicationException object with the text "This is a new exception", and then throwing and catching that exception:


10. Changes in Controls from VB6 to VB.net

By: Steven Holzner : 2010-11-17

Description: In fact, the Caption property no longer exists; it's been replaced by the Text property. There are other changes in controls from VB6 as well—and plenty of them. I'll take a look at a number of general points here to start us off.