Directives

10.1 Use Try…Catch…Finally to handle unexpected as well as anticipated exceptions.

Most exception handlers are designed to trap exceptions that aren’t anticipated at design time. Use a Try…Catch…Finally structure to catch all unanticipated exceptions.

Example. Incorrect:
							Private Sub btnSelectPicture_Click(ByVal sender As System.Object, _
                                   ByVal As System.EventArgs) Handles _
                                   btnSelectPicture.Click
   ’ Purpose   :  Open the selected picture and display it in the 
   ’              picture box.

   ’ Show the open file dialog box.
   
If ofdSelectPicture.ShowDialog = DialogResult.OK Then
       ’ Load the picture into the picture box.       picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName) ...

Get Practical Standards for Microsoft® Visual Basic® .NET, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.