VB.Net program to demonstrate the StackOverflowException

Here, we are going to demonstrate the StackOverflowException in VB.Net.
Submitted by Nidhi, on January 05, 2021 [Last updated : March 08, 2023]

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
    End Sub

    Sub Main()
        Catch e As StackOverflowException
        End Try
    End Sub
End Module


Process is terminated due to StackOverflowException.
Press any key to continue . . .


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 »

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.