Flylib.com

Books Software

 
 
 

Structured Exception Handling

Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Chapter 2.  Out with the Old, In with the New

Structured Exception Handling

Visual Basic .NET still supports On Error Goto error handling, but you should replace the old VB6 style On Error Goto statements with structured exception handling. (It's also likely that On Error Goto will be removed in future versions of VB; Microsoft is giving us a chance to get used to exceptions.)

Structured exceptions are one aspect of VB .NET that promote VB to a first-class language. Exceptions are subclassed from Objects and exception handling is more robust and precise than On Error Goto.

Exception handling was invented as a means of replacing the error-prone error code return value and supports writing more robust applications. Exception handling in VB .NET supports Try...Catch exception blocks and Try...Finally resource protection blocks. This topic requires more than a few paragraphs, so considerable coverage is provided in Chapter 3, "Basic Programming in VB .NET."


Team-Fly    
Top
 
Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Chapter 2.  Out with the Old, In with the New


Visual Basic .NET Handling of Reserved Words

Visual Basic .NET allows you to use reserved words in code. If you accidentally use a reserved word, such as Enum, as a variable, the IDE will place square brackets around the word. You can then use the reserved word in a non-reserved way as long as every occurrence has the brackets around the reserved word.

Using reserved words in this way probably isn't a good idea because it may lead to confusing, unsightly code. It's also a safe bet that this quirk won't survive for long.

Unfortunately, there are times when you may not be able to avoid using keywords, especially when they define a type. The System.Reflection namespace defines the type Assembly. Assembly is both a type and a keyword. When you declare Assembly variables , the code editor will add the brackets around the Assembly type declaration but may not always add the brackets, especially when a reserved word is used as a variable name .


Team-Fly    
Top
 
Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Chapter 2.  Out with the Old, In with the New

Compatibility Between VB6 and VB .NET

Experienced users of Visual Basic 6 will find that once they understand key differences between VB6 and VB .NET, it's possible to easily migrate VB6 code to the VB .NET environment.

Microsoft.VisualBasic

The Microsoft.VisualBasic compatibility namespace includes elements relevant to VB6 compatibility. If you open a VB6 project in VB .NET, the migration wizard will run. Migrating code from VB6 to VB .NET uses things from the compatibility namespace. For new code, I would suggest you use the new types, idioms, collections, and other features of VB .NET because elements of the Microsoft.VisualBasic compatibility namespace will probably find their way into the circular file soon.

Programming Elements Not in Visual Basic .NET

Many elements of VB6 didn't make it into VB .NET. Some aspects of VB6 were replaced and others are no longer supported. To provide you with a comprehensive table of VB6 elements, the elements that were left out of VB .NET are described in a table in Appendix A.Refer to Appendix A for a complete list of features that were revised or removed in VB .NET. (Many are covered in this chapter, but the table in Appendix A will provide you with one location for reference.)


Team-Fly    
Top