Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help error handling a windows service

Posted on 2016-10-05
2
Medium Priority
?
60 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

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 34

Accepted Solution

by:
it_saige earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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