Handling Errors with Structured Exception Handlers

With .NET, Visual Basic now supports structured exception handling. Structured exception handling, or SEH, provides developers with a powerful way of protecting specific blocks of code and reacting to specific classes of errors.

Note

Unstructured exception handling is also supported through the “old style” method of using On Error commands and inline procedure blocks for handling errors.

Structured Exception Handling

Consider the following code:

 Function SearchInFile(ByVal searchValue As String, _ ByVal fileName As String) As Boolean Dim reader As StreamReader Dim content As String reader = File.OpenText(fileName) content = reader.ReadToEnd() If InStr(content, searchValue) > 0 Then SearchInFile ...

Get Visual Basic® Programmer's Guide to the .NET Framework Class Library 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.