• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Aggregating ValidationExceptions in validateForSave()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Aggregating ValidationExceptions in validateForSave()


  • Subject: Aggregating ValidationExceptions in validateForSave()
  • From: Paul Hoadley <email@hidden>
  • Date: Wed, 14 Jan 2015 16:06:19 +1030

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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Aggregating ValidationExceptions in validateForSave()
      • From: Chuck Hill <email@hidden>
  • Prev by Date: Re: Model/DB synchronization (was: Migrations (was: ERXSQLHelper))
  • Next by Date: Websphere/other Appserver Deployment with two EARs/WARs in one Node?
  • Previous by thread: Re: maven.wocommunity.org is down
  • Next by thread: Re: Aggregating ValidationExceptions in validateForSave()
  • Index(es):
    • Date
    • Thread