Solved

Need help error handling a windows service

Posted on 2016-10-05
2
40 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 33

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Shortcut (VB) 4 34
vb.net checkbox 7 41
VB.Net How to Exit Sub - Exit Form??? 5 48
I need help converting a bitmap to an image in VB.Net 1 0
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

911 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

18 Experts available now in Live!

Get 1:1 Help Now