You are on page 1of 6

DEPARTMENT OF COMPUTER ENGINEERING

Subject: GAD Subject Code:22053

Semester: 04 Course: CO4I-B

Laboratory No: L003C Name of Subject Teacher: Prof. Poonam Pawar

Name of Student: Prajwal More Roll ID:22203B0048

Experiment No: 23

Title of Experiment Implement a program to handle runtime errors using

Exception handling

Program Code
1. Write any program using Exception handling.

Program:
Module Module1

Sub divExcept(ByVal a As Integer, ByVal b As Integer)

Dim res As Integer

Try

res = a \ b

Catch ex As DivideByZeroException

Console.WriteLine(" These exceptions were found in the program {0}", ex)

Finally
Console.WriteLine(" Division result is {0}", res)

End Try

End Sub

Sub Main()

divExcept(5, 0)

Console.WriteLine(" Press any key to exit...")

Console.ReadKey()

End Sub

End Module

Output:

Practical Related Questions


1. Write output of following code.

Module Module1

Sub Main()
Try

Throw New Exception("Mega-error")

Catch ex As Exception

Console.WriteLine(ex.Message)

End Try

Console.ReadLine()

End Sub

End Module

Output:

2. Write output of following code.

Module Module1

Sub Main()

Try

' Try to divide by zero.


Dim value As Integer = 1 / Integer.Parse("0")

' This statement is sadly not reached.

Console.WriteLine("Hi")

Catch ex As Exception

' Display the message.

Console.WriteLine(ex.Message)

End Try

End Sub

End Module

Output:

Exercise
1. Write a program for student registration using exception handling.

Module Module1
Dim name As String

Dim rollno As Integer

Dim per As Double

Dim ch As Boolean

Sub Form()

Console.WriteLine("Fill Registration Form: ")

Console.WriteLine("Enter name , rollno and percentage:")

name = Console.ReadLine()

rollno = Console.ReadLine()

per = Console.ReadLine()

End Sub

Sub Main()

Module1.Form()

Try

ch = per > 0 And per < 100

If ch Then

Console.WriteLine("Form Filled Sucessfully")

Else

Throw New Exception("Invalid-Range")

End If

Catch ex As Exception

Console.WriteLine(ex.Message)

End Try

Console.ReadKey()

End Sub

End Module
Output:

Dated signature of Teacher


Marks Obtained

ProcessRelated Product Total (50)


(35) Related (15)

You might also like