Not sure what language your program is written in, but I ran into the same type of problem when writing a windows service. What I did was to write a method that handles the AppDomain.CurrentDomain.UnhandledException event. That way if an exception occurs that you are not currently handling, it will allow to exit your code gracefully.