473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to handle errors by outputting to a log file?

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
*-----------------------*
Nov 21 '05 #1
4 1617
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

"JenHu" wrote:
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
*-----------------------*

Nov 21 '05 #2
"JenHu" <je**********@hotmail-dot-com.no-spam.invalid> schrieb:
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.


For more evolved solutions, take a look here:

Exception Management Application Block for .NET
<URL:http://msdn.microsoft.com/library/en-us/dnbda/html/emab-rm.asp>

log4net
<URL:http://logging.apache.org/log4net/>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
Herfried,
For more evolved solutions, take a look here:


More than what?

Cor
Nov 21 '05 #4
"Cor Ligthert" <no************@planet.nl> schrieb:
For more evolved solutions, take a look here:


More than what?


More than a simple solution that can be implemented within a few minutes
;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
4
by: bizt | last post by:
Hi, I am about to write an app that loads an XML file into memory and then outputs it. Anyway, the XML file is likely to grow and grow. Its sitting at about 37KB just now and is likely to double...
3
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
3
by: Peterwkc | last post by:
Hello all C++ expert programmer, I have a handle class which point to another class and use the pointer as object. I follow the code from C++ articles submited by someone in this forum....
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
2
bilibytes
by: bilibytes | last post by:
Hi, I have a database with a one to many relationship and i was wondering what was the best way to parse the resultset. this post explains exactly what my situation:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.