I’m pretty sure Chuck is always right™. Even when he answers a question 6 years before the code in question was released. If it’s between Chuck and Javadocs, my money is on Chuck ;-D
On Jan 14, 2015, at 11:23 AM, Chuck Hill <[email protected]> wrote: > IIRC, it should work like the first example, but it is possible that some > code is creating the thrown exception incorrectly. The last code example is > probably safe. > > Chuck > > On 2015-01-13, 9:36 PM, "Paul Hoadley" wrote: > > Hello, > > Just digging up a 12 year old thread on a different list here... > > http://webobjects-dev.omnigroup.narkive.com/qCLbaSnX/throwing-multiple-validation-errors-during-validateforsave > > Chuck suggests something like the following: > > public void validateForSave() throws ValidationException { > NSMutableArray exceptions = new NSMutableArray(); > try { > super.validateForSave(); > } catch (ValidationException e) { > exceptions.addObjectsFromArray(e.additionalExceptions()); > } > > // ... > > if (exceptions.count() > 0) { > throw ValidationException.aggregateExceptionWithExceptions(exceptions); > } > } > > Chuck, does that miss the case where super.validateForSave() just throws a > single exception e without nested exceptions? In that case, > e.additionalExceptions() will return an empty array, and e doesn't get added > to the exceptions array. That seems to be what's happening for me, anyway. > > I don't think this would be quite right: > > try { > super.validateForSave(); > } catch (ValidationException e) { > exceptions.add(e); > exceptions.addObjectsFromArray(e.additionalExceptions()); > } > > because the Javadocs suggest the container exception duplicates the first > exception in the array. > > http://wocommunity.org/documents/javadoc/WebObjects/5.4.2/com/webobjects/foundation/NSValidation.ValidationException.html#aggregateExceptionWithExceptions(com.webobjects.foundation.NSArray) > > How about this? > > try { > super.validateForSave(); > } catch (ValidationException e) { > if (e.additionalExceptions().count() > 0) { > exceptions.addObjectsFromArray(e.additionalExceptions()); > } else { > exceptions.add(e); > } > } > > I'll test it out, but if someone already knows, by all means jump in. > > > -- > Paul Hoadley > http://logicsquad.net/ > > > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list ([email protected]) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/webobjects-dev/rgurley%40smarthealth.com > > This email sent to [email protected]
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
