This document discusses exception handling in programming. It defines an exception as a problem that occurs during program execution, such as dividing by zero. It describes two types of exception handling: unstructured and structured. Unstructured handling uses if/else statements or On Error GoTo. Structured handling uses Try/Catch blocks with keywords like Try, Catch, Finally, and Throw to control program flow. It also shows exception class hierarchies and provides a code example using Try/Catch.
Definition and scope of exception handling in programming.
Definition and types of errors: Compile Time, Run Time, Syntactical, Logical errors.
Definition of exception handling and its purpose in program control flow.
Introduction to unstructured and structured exception handling methods. Two methods: 'On Error GoTo' and 'If...else' statements for unstructured handling.
Structured methods using Try, Catch, Finally, and Throw keywords, including VB.NET syntax.
Example code demonstrating structured exception handling with VB.NET.
Final slide thanking the audience for their attention.
C O N T E N T 01 Text Title Place yourown text here 02 Exception Handling 03 Unstructured Exception Handling 04 Types of Exception Handling 2 01 What is Exception? 05 Structured Exception Handling
EXCEPTION An exception refersto a problem that arises during program execution. It is brought about by an unexpected circumstance. A good example is when you are performing a division operation, and then you divide by zero (0). An exception will be raised. 5
Exception Handling 7 Exception handlingis the process of responding to the occurrence, during computation, of exceptions( anomalous or exceptional conditions requiring special processing ) often disrupting the normal flow of program execution.
On Error GoTo: Public Class Form1 Dim num1 As Integer Dim num2 As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim result As Integer On Error GoTo lbl num1 = CInt(TextBox1.Text) num2 = CInt(TextBox2.Text) funA() result = num1 num2 lbl: MsgBox(result) End Sub
13.
If…else : Public ClassForm1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim array As Integer() = New Integer(3) {} array(0) = 10 array(1) = 20 array(2) = 30 array(3) = 40 For i As Integer = 0 To array.Length - 1 MessageBox.Show(array(i)) Next End Sub End Sub
Structured Exception Handling 15 With exceptionhandling, you can transfer the control of a program from one part to another. In VB.NET, exceptions are handled in Structured way using 4 keywords:
Keyword Detail Try The workof the Try block is to identify the code block for which a specific exception will be activated. It should be followed by a catch block(s). Catch Catching of the Exception is done in this block. It is an exception handler in which the Exception is handled. Finally Use the Finally block to run a set of statements whether an exception has occurred or not. Throw An exception is thrown after the occurrence of a problem. This is the work of the Throw keyword.
18.
Syntax of Try/Catch 18 Try [try_Statement(s) ] [ Exit Try ] [ Catch [ exception_name [ As type ] ] [ When expression ] [ catch_Statement(s) ] [ Exit Try ] ] [ Catch ... ] [ Finally [ finally_Statement(s) ] ] End Try
19.
Public Class Form1 Dimnum1 As Integer Dim num2 As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim result As Integer Try num1 = CInt(TextBox1.Text) num2 = CInt(TextBox2.Text) funA() result = num1 num2 Catch ex As DivideByZeroException MsgBox(ex.Message) Finally MsgBox(result) End Try End Sub Public Function funA() As Integer Dim result As Integer num1 = CInt(TextBox1.Text) num2 = CInt(TextBox2.Text) If num2 = 0 Then Throw New DivideByZeroException("plz enter denominator greater then 0") End If result = num1 num2 End Function End Class