Set Exception HelpLink : Exception « Development « VB.Net Tutorial






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.








7.4.Exception
7.4.1.Basics of Visual Basic exception handling
7.4.2.Use properties Message, StackTrace and InnerException
7.4.3.Get Message from Exception
7.4.4.Convert Exception to String
7.4.5.Exception fields
7.4.6.Display Exception Trace
7.4.7.Throw Exception out of a Method
7.4.8.Catch Exception in a function
7.4.9.Set Exception HelpLink
7.4.10.Serializable Exception Inheriting NullReferenceException
7.4.11.Catch divided by zero exception
7.4.12.Throw Your own exception in class constructor