How to handle errors by outputting to a log file?

  • Thread starter Thread starter JenHu
  • Start date Start date
J

JenHu

I have a vb.net application, which read the text file line by line and
write into SQL server tables. The text file contains the employees'
bank account number and all other information.

The way I handle the error is stopping process and send an error
message to the screen
Try .......
Catch err As Exception
MsgBox(err.Message)
End Try

However, that stops the process.

I want to output the error message and kick the whole line for this
employee out of the process and output into a log file, then the
process will continue until end of file.

Can someone give me an idea of how to?

Thank you.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Dim strErrorFile As String = "C:\ErrorLog.log"

Private Sub LogError(ByVal sError As String, ByVal sFilename As String)
Dim sw As New IO.StreamWriter(sFilename, True)
sw.WriteLine(sError)
sw.Flush()
sw.Close()
End Sub

Try
' Do something
Catch ex As Exception
LogError(ex.ToString, strErrorFile)
End Try

or

Private Sub LogError(ByVal sError As String)
Dim sw As New IO.StreamWriter("C:\ErrorLog.log", True)
sw.WriteLine(sError)
sw.Flush()
sw.Close()
End Sub

with

Try
' Do something
Catch ex As Exception
LogError(ex.ToString)
End Try

I hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top