<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Exception eaten in Windows service?</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Exception eaten in Windows service?</description>
  <pubDate>Sat, 11 Apr 2026 01:09:44 -700</pubDate>
  <lastBuildDate>Fri, 04 Oct 2013 11:30:48 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=4459</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Exception eaten in Windows service? : Yep, that was it. If I try catching...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4459&amp;PID=17019#17019</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=627" rel="nofollow">stevenr</a><br /><strong>Subject:</strong> 4459<br /><strong>Posted:</strong> 04-Oct-2013 at 11:30am<br /><br />Yep, that was it. If I try catching "Exception", it is logged.]]>
   </description>
   <pubDate>Fri, 04 Oct 2013 11:30:48 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4459&amp;PID=17019#17019</guid>
  </item> 
  <item>
   <title>Exception eaten in Windows service? : DevForce does not eat the exception,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4459&amp;PID=17016#17016</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 4459<br /><strong>Posted:</strong> 04-Oct-2013 at 10:02am<br /><br /><P sab="961">DevForce does not eat the exception, and does not know that it's&nbsp;running within the context of&nbsp;a Windows Service.</P><DIV sab="962"></DIV><DIV sab="963"></DIV><DIV sab="964"></DIV><DIV sab="965">Your DoWork method is running on a background thread, and I have read that exceptions on a background thread may not always be handled by an AppDomain.CurrentDomain.UnhandledException handler.&nbsp; It's odd, though, that your try/catch handler isn't catching the exception, although you could try catching "Exception" and not "SystemException", since the exception thrown by DevForce will likely be a PersistenceServerException, which doesn't inherit from SystemException.</DIV><DIV sab="966">&nbsp;</DIV><DIV sab="967">Another thing to try is to add a handler for PM.PersistenceServerError.&nbsp; &nbsp;</DIV>]]>
   </description>
   <pubDate>Fri, 04 Oct 2013 10:02:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4459&amp;PID=17016#17016</guid>
  </item> 
  <item>
   <title>Exception eaten in Windows service? : The system I&amp;#039;m working on...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4459&amp;PID=17010#17010</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=627" rel="nofollow">stevenr</a><br /><strong>Subject:</strong> 4459<br /><strong>Posted:</strong> 04-Oct-2013 at 5:43am<br /><br />The system I'm working on consists of a client application where users can submit requests for work in a database table, and a Windows service that polls this table every x seconds. If there is work to be done, the service calls into a module that processes the request. If there is no work to be done, the service goes back to sleep and checks again in x seconds. This is all set up and has been working for almost a year now. The problem is that recently, there were cases being reported of requests for work that were submitted, but never processed. Upon further investigation, I learned that the service had run into an unhandled exception but that exception was never caught and logged. Here's the main part of the service:<br /><br />private void Timer_Elapsed(object sender, ElapsedEventArgs e)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;try<br />&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check if there is work to be done<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (there is work to be done)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.timer.Stop();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Call the module that does the actual work<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyWorkerModule.DoWork();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;catch (SystemException ex)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Log the exception<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;finally<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!this.timer.Enabled)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.timer.Start();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />The service also handles the AppDomain.CurrentDomain.UnhandledException event where it logs any exceptions.<br /><br />My first approach was to find out if there was anything wrong with the implementation of the service itself. I have a command-line executable that I use for actual debugging that follows the exact same code path as the service and the executable does catch the exception. Here's the full stack trace that the executable caught:<br /><br />IdeaBlade.Persistence.PersistenceServerException: The conversion of a datetime data type to a smalldatetime data type resulted in an out-of-range value.<br />The conversion of a datetime data type to a smalldatetime data type resulted in an out-of-range value. ---&gt; System.Data.SqlClient.SqlException: The conversion of a datetime data type to a smalldatetime data type resulted in an out-of-range value.<br />The conversion of a datetime data type to a smalldatetime data type resulted in an out-of-range value.<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.RemotingPersistenceServerProxy.CheckConnection(Exception pException)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceServerProxy.Fetch(SessionBundle pBundle, IEntityQuery pQuery)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.XFetchDataSet(IEntityQuery pEntityQuery)<br />&nbsp;&nbsp;&nbsp;--- End of inner exception stack trace ---<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.HandlePersistenceServerException(Exception pException, Boolean pTryToHandle, PersistenceOperation pOperation)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.XFetchDataSet(IEntityQuery pEntityQuery)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.XFetch(IEntityFinder pEntityFinder, WorkState pWorkState)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.XFetch(IEntityQuery pEntityQuery, QueryStrategy pQueryStrategy, WorkState pWorkState)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.XGetEntities(IEntityQuery pEntityQuery, QueryStrategy pQueryStrategy, WorkState pWorkState)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.GetEntity(IEntityQuery pEntityQuery, QueryStrategy pQueryStrategy)<br />&nbsp;&nbsp;&nbsp;at IdeaBlade.Persistence.PersistenceManager.GetEntity&#091;T&#093;(IEntityQuery pEntityQuery, QueryStrategy pQueryStrategy)<br /><br /><br />I even tried catching and logging unhandled exceptions in the worker module itself:<br /><br />public class MyWorkerModule<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;public void DoWork()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Actual work done here.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (SystemException e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Log the exception<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />But whatever I do, the service just won't catch and log the exception. I posted this question on MSDN and the response I got was that the way this service is implemented, it should be able to catch exceptions.  After exhausting every avenue, I have come to believe that somehow IdeaBlade eats the exception somewhere along the way, *only* when executing from within the context of a service (remember, a command-line executable following the exact same code path does catch the exception). I'm not concerned about recovering from the exception; my goal here is to know that an exception occurred because a request can consist of thousands of records to be processed and it would be very helpful to know exactly where a problem occurs.<br />So my question is: is there a particular setting that I need to configure to allow the exception to reach the catch block? The service runs on .Net 3.5 on Windows Server 2008.]]>
   </description>
   <pubDate>Fri, 04 Oct 2013 05:43:16 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4459&amp;PID=17010#17010</guid>
  </item> 
 </channel>
</rss>