VB.Net program to demonstrate the DivideByZeroException

Here, we are going to demonstrate the DivideByZeroException in VB.Net.
Submitted by Nidhi, on January 05, 2021

Here, we demonstrate the divide by zero exception. As we know that the divide zero operation is not valid, that’s why to handle the exception, we need to use DivideByZeroException class in the catch block.

Program/Source Code:

The source code to demonstrate the DivideByZeroException is given below. The given program is compiled and executed successfully.

'Vb.Net program to demonstrate the DivideByZeroException.

Module Module1
    Sub Main()
        Dim num1 As Integer = 10
        Dim num2 As Integer = 0
        Dim num3 As Integer = 0

        Try
            num3 = num1 \ num2
            Console.WriteLine("Result is: {0}", num3)
        Catch e As DivideByZeroException
            Console.WriteLine(e.Message)
        End Try
    End Sub
End Module

Output:

Attempted to divide by zero.
Press any key to continue . . .

Explanation:

In the above program, here we created a module Module1. The Module1 contains Main() function.

The Main() is the entry point for the program, here we created three local variables num1, num2, and num3. Which are initialized with 10, 0, 0 respectively.

Here we defined the Try block to handle exceptions. The above will generate DivideByZeroException because we are trying to divide an integer value by zero in the below statement.

num3 = num1 \ num2





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.