Solved

Need help error handling a windows service

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error import assembly 19 30
How do i create a simple array in a public class? 6 37
EF5 How do I stop pre-compiled views? 8 54
Javascript function 3 21
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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