none
Err.Number and Err.Description

    Question

  •  Hi,

    I used following code to write error in .txt file by using Microsoft.VisualBasic namespace. It works fine, but I dont want to use this namespace. Because my application is in VB.Net 2.0 and i want alternate code in Vb.net 2.0

    If
    Err.Number <> 0 Then

    errLogStreamWriter = New System.IO.StreamWriter(My.Application.Info.DirectoryPath & "\ErrorLog.txt", True)

    errLogStreamWriter.WriteLine(Err.Source + Space(2) + Err.Description + Space(2) + CStr(DateTime.UtcNow()) + " UTC DATE/TIME")

    errLogStreamWriter.WriteLine()

    errLogStreamWriter.Close()

    Resume Next 

    End If


    Can anyone suggest me any solution? 

    Tuesday, December 16, 2008 9:23 AM

Answers

  • Hi,

    with Err.Number you reference to VB6 I think!?! Well, there is a different way to catch errors in VB.Net or C# and so on.
    Just use the "Try-Catch-Block"

    \\\
            Try
                 'Your Program Code goes here
            Catch ex As Exception
                 'Your Error handling goes here
                 'Messagebox.Show(ex.Message) or Messagebox.Show(ex.Source) and so on
            End Try
    ///

    Tuesday, December 16, 2008 9:55 AM