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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.