Programming Tutorials

VB.net Tutorials

11. Properties in VB.net

By: Steven Holzner : 2010-11-17

Description: Visual Basic objects can have methods, fields, and properties. If you've worked with Visual Basic before, you're familiar with properties, which you use to set configuration data for objects, such as the text in a text box or the width of a list box. Using properties provides you with an interface to set or get the value of data internal to an object. You declare properties using Get and Set procedures in a Property statement (and, as you might expect, the syntax has changed from VB6):


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


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


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


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


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


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


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


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