Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the OverflowException
By Nidhi Last Updated : November 13, 2024
OverflowException in VB.Net
Here, we will demonstrate the OverflowException, when we multiply two big integer numbers then the result will generate an OverflowException.
Program/Source Code:
The source code to demonstrate the OverflowException is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of OverflowException
'Vb.Net program to demonstrate the OverflowException.
Imports System.IO
Module Module1
Sub Main()
Try
Dim num As Integer = 100000
Dim result As Integer = 0
result = num * num
Console.WriteLine("Square is: {0}", result)
Catch ex As OverflowException
Console.WriteLine("Exception: " & ex.Message)
End Try
End Sub
End Module
Output
Exception: Arithmetic operation resulted in an overflow.
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains a function Main().
The Main() function is the entry point for the program. Here, we created an integer number, which is initialized with 100000. Then we multiply the number by itself to calculate the square of the number. Then OverflowException gets generated that will be caught in the catch block and print the appropriate message on the console screen.
VB.Net Exception Handling Programs »