Exceptions V2 Learn programming Visual Basic (VB.net)

Lesson:

Basic Data Types


Exercise:

Exceptions V2 55


Objetive:

Create a program to ask the user for a real number and display its square root. Errors must be trapped using "try..catch".

Does it behave as you expected?


Code:

Imports System
Public Class exercise71
    Public Shared Sub Main()
        Dim result As Single
        Dim num As Single
        Console.Write("Enter Number ")

        Try
            num = Convert.ToSingle(Console.ReadLine())
            result = CSng(Math.Sqrt(num))
            Console.WriteLine("The result is: {0}", result)
        Catch __unusedException1__ As Exception
            Console.WriteLine("Error, I cannot calculate the Square Root")
        End Try
    End Sub
End Class