Option Strict On
Imports System
Class Tester
Public Shared Function DoDivide(ByVal a As Double, ByVal b As Double) As Double
If b = 0 Then
Dim e As New System.DivideByZeroException( )
e.HelpLink = "http://www.java2s.com"
Throw e
End If
If a = 0 Then
Throw New System.ArithmeticException( )
End If
Return a / b
End Function 'DoDivide
Shared Sub Main( )
Try
Dim a As Double = 5
Dim b As Double = 0
Console.WriteLine("{0} / {1} = {2}", a, b, DoDivide(a, b))
Catch e As System.DivideByZeroException
Console.WriteLine("DivideByZeroException! Msg: {0}", e.Message)
Console.WriteLine("Helplink: {0}", e.HelpLink)
Console.WriteLine("Stack trace: {0}", e.StackTrace)
Catch
Console.WriteLine("Unknown exception caught!")
Finally
Console.WriteLine("Close file here.")
End Try
End Sub 'Main
End Class 'Tester
DivideByZeroException! Msg: Attempted to divide by zero.
Helplink: http://www.java2s.com
Stack trace: at Tester.DoDivide(Double a, Double b)
at Tester.Main()
Close file here.