JK VB - NET - 9 Exception Handling
JK VB - NET - 9 Exception Handling
n2 = num2.Text
r = n1 / n2
MessageBox.Show(r)
► Error Handling is an essential part of any good
code.
► Exception
An indication of a problem that occurs during a
program’s execution
System.Exception is the base class for all
exceptions
The coding structure VB.NET uses to deal with
End Try
Try Block
► Means “ Try to execute this code “
matches
Finally Block
► Programs that obtain certain resources must
return them explicitly to avoid resource leaks
► Finally block
Optional in a Try statement
one)
Executes whether or not an exception is
connection
Try
n1 = num1.Text
n2 = num2.Text
r = n1 / n2
MessageBox.Show(r)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
DivideByZeroTest
Try: A Try block identifies a block of code for which
particular exceptions will be activated. It's followed by
one or more Catch blocks.
Catch ex As Exception
MsgBox(ex.Message)
'Catch ex As Exception
' MsgBox("an error has occurred" & Environment.NewLine & ex.ToString())
Finally
MsgBox("am the finally")
End Try
Revision Questions