Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the StackOverflowException
By Nidhi Last Updated : November 13, 2024
What is a StackOverFlow exception in VB.Net?
Here, we will demonstrate the StackOverflowException, this exception will be generated by the infinite recursive function call.
Program/Source Code:
The source code to demonstrate the StackOverflowException is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of StackOverflowException
'Vb.Net program to demonstrate the StackOverflowException
Module Module1
Dim num As Integer = 10000
Sub RecursiveFun()
num = num + 10000
RecursiveFun()
End Sub
Sub Main()
Try
RecursiveFun()
Catch e As StackOverflowException
Console.WriteLine(e.Message)
End Try
End Sub
End Module
Output
Process is terminated due to StackOverflowException.
Press any key to continue . . .
Explanation
In the above program, here we created a module Module1. The Module1 contain two functions RecursiveFun(), Main() function.
The RecursiveFun() function has an infinite recursive call that's why it will generate StackOverflow Exception.
The Main() is the entry point for the program, here we called the RecursiveFun() function that will be caught in the catch block and print an appropriate message on the console screen.
VB.Net Exception Handling Programs »