Solved

Need help error handling a windows service

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 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