unstructured exception handling

+1 Ankit Ojha · November 29, 2015
Module Module1

    Sub Main()
        Dim a, b, c As Integer
        On Error GoTo la
        Console.WriteLine("enter a and b")
        a = Console.ReadLine()
        b = Console.ReadLine()
        c = a / b
        Console.WriteLine("result" & c)
        Console.WriteLine("caught an exception")
        Resume Next

    End Sub

End Module

Why in the code "caught an exception" gets executed 3 times

Post a Reply


Oldest  Newest  Rating
0 Ankit Ojha · December 3, 2015

yes i know we use structured exception handling today it's just i have a viva for my end semester so wanted to know that.
0 Fernando Portilla · November 30, 2015
You are trying :

  1. Integer division by 0

  2. To assign the result of this to another Integer

You need an 'Exit Sub' statement before the 'la:' label; otherwise the code underneath is executed one more time after
the statement 'Console.WriteLine("result" & c)' is processed.

Have a look at your Inmediate Window (CTRL-G) for a detail of exceptions generated by your code.

BTW 'On Error Goto (Label)'  and 'RESUME NEXT' is fairly old style coding practice, going back to Microsoft GWBASIC in MS-DOS and CP/M. I would say the code is deprecated nowadays. You might have a look at try...catch instead.
0 Ankit Ojha · November 29, 2015
  • 1

Visual Basic


One of the first products to provide a graphical environment and a paint metaphor for developing user interfaces.

Bucky Roberts Administrator