How to extract info from DataPortalException.BusinessObject to understand an exception
How to extract info from DataPortalException.BusinessObject to understand an exceptionOld forum URL: forums.lhotka.net/forums/t/7839.aspx
jgamba posted on Wednesday, October 21, 2009Dear all...
My staff are building a exception Custom Handler for understand the info contained in
DataPortalException.BusinessObject at UI Layer. I found this thread http://forums.lhotka.net/forums/thread/22952.aspx, there Rocky comments about this topic:
"This is part of the behavior of the DataPortalException - it brings back the object as it was at the time of the exception. The purpose behind doing this is to provide you with complete information for debugging or otherwise attempting to understand the reason for the exception."
My concern is: any reference code about?
Say you that I have a parent object with children objects, so one of them fails saving, I want to signal exactly to the end-user how to identify the erroneous child with Additional information to understand the reason for an exception.
thanks in advance
RockfordLhotka replied on Thursday, October 22, 2009
I have never viewed that feature as a way to generate end-user output. I have always viewed it as a way for a developer to debug or troubleshoot an issue during development.
I'm not sure there's any way to automate around this. Every object graph is different, and generally speaking there's no sure way to know which object in the graph caused the failure.
Henrik replied on Friday, October 23, 2009You need to know which exception is raised, for example a duplicate primary key SQLException. You’ll need to catch this in the DataPortal_xxx method. To solve it you’ll need to create a new specific exception subclass like: ItemAlreadyExistsException, that can carry the child objects unique id/primary key. When you catch the exception, you stuff the unique child id into the exception and the UI will then be able to identify which child that caused the exception.
Notice though, that this will only work for the first child object that causes an exception. A better way would be to add a validation rule that checks for duplicate keys, invalid data or whatever. This way you’ll be able to display the validation errors for each object.
Copyright (c) Marimer LLC