VB.net Tutorials

11. Understanding Scope in VB.net

By: Steven Holzner : 2010-11-17

Description: The scope of a variable or constant is the set of all code that can refer to it without qualifying its name. A variable's scope is determined by where the variable is declared. It's usually a good idea to make the scope of variables or constants as narrow as possible (block scope is the narrowest). This helps conserve memory and minimizes the chances of your code referring to the wrong item. I'll take a look at the different kinds of scope in VB .NET here.


12. 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:


13. 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:


14. 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:


15. 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:


16. 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.


17. 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:


18. 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:


19. 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:


20. 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: