<?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 : Exceptions and EntityManager.EntityChaged event</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Exceptions and EntityManager.EntityChaged event</description>
  <pubDate>Tue, 12 May 2026 23:25:10 -700</pubDate>
  <lastBuildDate>Tue, 27 Nov 2012 15:27:12 -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=2634</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>Exceptions and EntityManager.EntityChaged event :   We added this fix at the request...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=15288#15288</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> 2634<br /><strong>Posted:</strong> 27-Nov-2012 at 3:27pm<br /><br />We added this fix at the request of our Professional Services group, and after much debate it was specifically made only for add and attach actions.&nbsp;&nbsp;The&nbsp;argument for swallowing&nbsp;exceptions thrown during AddOnQuery&nbsp;(and AddOnImport) was that "failing in the middle of a query is usually not what the developer actually intended" because it was more likely to occur due to a badly written event handler.&nbsp; We can revisit this, but in truth you're better off leaving your workaround in place for now.<div></div><div></div>]]>
   </description>
   <pubDate>Tue, 27 Nov 2012 15:27:12 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=15288#15288</guid>
  </item> 
  <item>
   <title>Exceptions and EntityManager.EntityChaged event :  I&amp;#039;m going to bring back...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=15286#15286</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2634<br /><strong>Posted:</strong> 27-Nov-2012 at 2:21pm<br /><br /><div>I'm going to bring back this old thread because I noticed that part of this issue has been addressed in 6.1.9.0. &nbsp;I saw this in the release notes:<div><br></div></div><blockquote style="margin: 0 0 0 40px; border: n&#111;ne; padding: 0px;"><div><div>Exceptions thrown in EntityChanging/EntityChanged handlers will not be "eaten" for add/attach actions. &nbsp;&#091;D2238&#093;</div></div></blockquote><div><div><br></div></div><div>I'm not sure how that fix all of a sudden made it in but I like it. &nbsp;One thing....that only covers the case where EntityChanging/Changed gets fired because of an Add or Attach. &nbsp;But what about AddOnQuery? &nbsp;That is a big one for us where we often do initialization type logic when the entity is first loaded as part of a query - and we do not want exceptions thrown there to be swallowed. &nbsp;We also do logic for other EntityActions. &nbsp;Is there a reason that this change was limited to just Add/Attach? &nbsp;Any chance that this could be extended to more (all?) Entity Actions?</div><div><br></div><div>Thanks,</div><div>-Stephen</div>]]>
   </description>
   <pubDate>Tue, 27 Nov 2012 14:21:25 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=15286#15286</guid>
  </item> 
  <item>
   <title>Exceptions and EntityManager.EntityChaged event : It works fine on the client side....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10548#10548</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2634<br /><strong>Posted:</strong> 26-Apr-2011 at 2:49pm<br /><br />It works fine on the client side. &nbsp;Our client is a Silverlight app and we have some "catch all" error handling in the Application.UnhandledException event (that manages to catch exceptions thrown on any thread).<div><br></div><div>I imagine this approach won't work so well if it executes on the BOS though. &nbsp;I don't know if maybe the exception in the new thread will be lost. &nbsp;Also, the client will not be notified of any problems and won't have any way of knowing that the query/save/etc. threw exceptions on the server. &nbsp;Is there anything I could do in server-side code so this error won't be hidden from the client? &nbsp;Something like App.Current.Shutdown only really makes sense on the client but not on the BOS.</div><div><br></div><div>Thanks for the help,</div><div>-Stephen</div>]]>
   </description>
   <pubDate>Tue, 26 Apr 2011 14:49:01 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10548#10548</guid>
  </item> 
  <item>
   <title>Exceptions and EntityManager.EntityChaged event : Stephen,  In your workaroud,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10546#10546</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2634<br /><strong>Posted:</strong> 26-Apr-2011 at 2:39pm<br /><br />Stephen,<DIV>&nbsp;</DIV><DIV>In your workaroud, doesn't the exception get "lost/swallowed" in/with the new thread? That'd be the only issue I see with your proposed solution.</DIV><DIV>&nbsp;</DIV><DIV>Another approach would be&nbsp;having a try/catch in your logic and writting to log/exiting the app ( App.Current.Shutdown() ) there. </DIV><DIV>&nbsp;</DIV><DIV>Silvio.</DIV>]]>
   </description>
   <pubDate>Tue, 26 Apr 2011 14:39:39 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10546#10546</guid>
  </item> 
  <item>
   <title>Exceptions and EntityManager.EntityChaged event : For us, exceptions thrown while...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10533#10533</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2634<br /><strong>Posted:</strong> 25-Apr-2011 at 7:33pm<br /><br />For us, exceptions thrown while we are doing entity initialization are fatal errors. &nbsp;In production, fatal errors are logged, displayed to the user and then the application is be brought down to stop the user from continuing when things are in an unstable/unpredictable state (in DEBUG mode, it's a bit different because we don't bring down the whole application but we still want to know about these errors).<div><br></div><div>In fact, our desired behavior is exactly what you describe: "...<span ="Apple-style-span" style="-webkit-border-horiz&#111;ntal-spacing: 1px; -webkit-border-vertical-spacing: 1px; ">if any exception were to be thrown, the entire thing would fail." &nbsp;We do want the entire thing to fail - that's why we threw an exception :-)</span><br><div><br></div><div>The way it is now, since these exceptions get swallowed, the application continues without any hint that something has gone wrong. &nbsp;The best solution I've come up with so far is the following but it feels so wrong, I was hoping there would be a better way:</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode">if (e.Action.In(EntityAction.AddOnQuery, EntityAction.AddOnAttach,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntityAction.AddOnImport, EntityAction.Add,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntityAction.ChangeCurrentAndOriginal))</div><div>{</div><div>&nbsp;&nbsp; &nbsp;//HACK: DevForce swallows exceptions in this method if the entity is being added.</div><div>&nbsp;&nbsp; &nbsp;//To get around that, we'll catch any exceptions and re-throw them on a new</div><div>&nbsp;&nbsp; &nbsp;// &nbsp; thread (in addition to this one) so they will be picked up by the&nbsp;</div><div>&nbsp;&nbsp; &nbsp;// &nbsp; exception processing code and will be visible.</div><div>&nbsp;&nbsp; &nbsp;try</div><div>&nbsp;&nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;InitializeEntity((AlliantEntity) e.Entity);</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;catch (Exception ex)</div><div>&nbsp;&nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//Throw the exception in a new thread</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;new Thread(</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;() =&gt;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw new AlliantApplicationException(</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Exception thrown during entity initialization and may have been swallowed. &nbsp;See inner exception.",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ex);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}).Start();</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;//And throw the exception to our caller</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;throw;</div><div>&nbsp;&nbsp; &nbsp;}</div><div>}</pre></td></tr></table></div></div><div><br></div><div>Thanks</div>]]>
   </description>
   <pubDate>Mon, 25 Apr 2011 19:33:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10533#10533</guid>
  </item> 
  <item>
   <title>Exceptions and EntityManager.EntityChaged event : Hi Stephen,   What do you exactly...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10532#10532</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2634<br /><strong>Posted:</strong> 25-Apr-2011 at 3:58pm<br /><br /><P>Hi Stephen, </P><DIV>&nbsp;</DIV><DIV>What do you exactly intend to do if an exception is thrown? While you can't propagate the exception, you can have a try/catch in your logic and add any found error to the ValidationErrors collection of the entity:</DIV><DIV>&nbsp;</DIV><DIV><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>myEntity.EntityAspect.ValidationErrors.Add(</FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>new</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>VerifierResult</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>(</FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>VerifierResultCode</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>.Error, </FONT></FONT><FONT color=#a31515 size=2 face=C&#111;nsolas><FONT color=#a31515 size=2 face=C&#111;nsolas><FONT color=#a31515 size=2 face=C&#111;nsolas>"meaningful msg"</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>));</FONT></FONT></FONT></FONT></FONT></DIV><DIV><DIV>&nbsp;</DIV><DIV>The reason the exception can't be propagated is that a query is an atomic operation and if any exception were to be thrown, the entire thing would fail.</DIV><DIV>&nbsp;</DIV><DIV>Silvio.</DIV></DIV>]]>
   </description>
   <pubDate>Mon, 25 Apr 2011 15:58:14 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10532#10532</guid>
  </item> 
  <item>
   <title>Exceptions and EntityManager.EntityChaged event : We have some initialization logic...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10525#10525</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2634<br /><strong>Posted:</strong> 22-Apr-2011 at 4:41pm<br /><br /><p>We have some initialization logic that needs to happen for entities as they get added to an Entity Manager. &nbsp;Currently, this is fired off from an event handler on EntityManager.EntityChanged. &nbsp;This has worked well for us except for one thing. &nbsp;If an exception is thrown in our initialization, it sometimes gets "swallowed". &nbsp;After some fun times with Reflector, I noticed that EntityManager.OnEntityChanged is the one that is swallowing the exception if IsLoadingEntity is true. &nbsp;This behavior might be nice for some cases, but in our case we want to know about these exceptions.</p><p>I was hoping I could just override OnEntityChanged to call my initialization logic directly (before calling base.OnEntityChanged() to raise the event). &nbsp;This way, I'd be in control of the error handling, but OnEntityChanged is internal so I can't do that.</p><p>Would it be possible for OnEntityChanged to not be internal? &nbsp;Or is there some other way I can have the exceptions not be swallowed?</p><p>Thanks,</p><p>-Stephen</p>]]>
   </description>
   <pubDate>Fri, 22 Apr 2011 16:41:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2634&amp;PID=10525#10525</guid>
  </item> 
 </channel>
</rss>