CSLA Light - Exceptions
Old forum URL: forums.lhotka.net/forums/t/7009.aspx
CampbellCM posted on Wednesday, May 27, 2009
I've run into a problem where my exceptions are getting squashed. I am throwing a specific exception in a Child_Update method but as it percolates up through the DataPortal_Update method it is getting squashed by a DataPortalException. I could live with that if the original exception was included as an InnerException but that's not the case. I don't want to show my users a DataPortalException message, I want to show them the original exception message that explains what went wrong.
Any suggestions?JoeFallon1 replied on Wednesday, May 27, 2009
The use of DataPortalException is by design. Since that is the way it works you are expected to catch that exception in your UI code. You could create a recursive GetLowestException function if you want to always get the innermost exception and display that ex.message to your users. It is up to you to decide what do with the DPEx.One of its features is that it contains the broken BO graph inside of it - so you could refer to its properties if you needed to.
Joe
RockfordLhotka replied on Wednesday, May 27, 2009
DataPortalException has a BusinessException property that should return the original exception that triggered everything.
CampbellCM replied on Wednesday, May 27, 2009
Thanks for the responses.
I'm "catching" the exception in the form of a Csla.Core.SavedEventArgs.Error and I don't see a BusinessException property.RockfordLhotka replied on Wednesday, May 27, 2009
I think that Error property returns something of type Exception.
You’d need to cast that value to DataPortalException to get at the extra
properties.
CampbellCM replied on Wednesday, May 27, 2009
Under the described circumstances, will I always see a DataPortalException?RockfordLhotka replied on Wednesday, May 27, 2009
No, there are other options.
I'd write my code like this:
Exception error = sourceobject.Error;
var dpe = ...Error As DataPortalException;
if (dpe != null)
error = dpe.BusinessException;
// process Exception in the error field hereCampbellCM replied on Thursday, May 28, 2009
DataPortalException does not have a BusinessException property, not on the SL client anyway.RockfordLhotka replied on Thursday, May 28, 2009
I apologize, I forgot we were talking about Silverlight.
As this question has come up a couple times on the forum in the past month,
I've added this answer to the FAQ:
http://www.lhotka.net/cslanet/faq/SilverlightFaq.ashx
RockyCampbellCM replied on Thursday, May 28, 2009
Thank you Rocky, that's what I needed.Copyright (c) Marimer LLC