Solved

Need help error handling a windows service

Posted on 2016-10-05
2
36 Views
Last Modified: 2016-10-05
Good morning Experts,
I need help error handling a windows service I wrote in VB.Net.

I put all of my processes in a Try \ Catch block.  When an error is encountered the code in the Catch executes and logs the error.
I want to prevent the service from stopping and to just continue to process the next record.  How can I do this?

thanks,
mrotor
0
Comment
Question by:mainrotor
2 Comments
 
LVL 22

Expert Comment

by:Snarf0001
ID: 41830392
It should already be doing that.  As long as you're not rethrowing in the catch block, then it won't stop the service.

If it is, you must have another failing block somewhere that's not wrapped in a try.
If you can post the code / error message, can see.
0
 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
ID: 41830411
It depends on your logic...  You may put everything into a try...catch block but you need to understand what that means and how it can affect the flow of your logic.

For example, what is the difference between this:
Module Module1
	Sub Main()
		Console.WriteLine("Starting Service")
		RunService()
		Console.WriteLine("Exiting Service")
		Console.ReadLine()
	End Sub

	Sub RunService()
		Try
			While (True)
				Console.WriteLine("Processing...")
				Throw New Exception("Exception Thrown")
			End While
		Catch ex As Exception
			Console.WriteLine(ex.Message)
		End Try
	End Sub
End Module

Open in new window


And this:
Module Module1
	Sub Main()
		Console.WriteLine("Starting Service")
		RunService()
		Console.WriteLine("Exiting Service")
		Console.ReadLine()
	End Sub

	Sub RunService()
		While (True)
			Try
				Console.WriteLine("Processing...")
				Throw New Exception("Exception Thrown")
			Catch ex As Exception
				Console.WriteLine(ex.Message)
			End Try
		End While
	End Sub
End Module

Open in new window


The difference is the location of the exception.  The first code example will stop processing when the the first exception is thrown because the try...catch encloses the processing loop; e.g. -Capture.JPGWhereas, the second code example will continue to run into perpetuity; e.g. -Capture.JPG
So, again, it comes down to your logic and it's layout.

-saige-
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now