• 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
Re: Validation exceptions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Validation exceptions


  • Subject: Re: Validation exceptions
  • From: Ed Powell <email@hidden>
  • Date: Sun, 5 Jan 2003 09:04:46 -0600 (CST)

Yeah, it occured to me that having the masterStringValidator code in my
original email would help, after I sent it... :)   I just don't like
showing my code to people... they tend to cringe...


private String masterStringValidator(String property, String data, boolean trimIt)
throws NSValidation.ValidationException {

        // Get the length values from the app properties
        Integer minLength = new
Integer(Integer.parseInt(Application.properties.getProperty("VALIDATE_"+property+"MinLength")));
        Integer maxLength = new
Integer(Integer.parseInt(Application.properties.getProperty("VALIDATE_"+property+"MaxLength")));

        // Check if what we have is null
        if (data == null) {
            throw new
NSValidation.ValidationException(Application.properties.getProperty("VALIDATE_"+property+"NullError"));
        }

        // If requested, trim the data
        if (trimIt == true) {
            data.trim();
        }

        // Validate the length of the string
        if ( (data.length() < minLength.intValue()) ||
             (data.length() > maxLength.intValue()) ) {
            throw new
NSValidation.ValidationException(Application.properties.getProperty("VALIDATE_"+property+"LengthError"));
        }

        // Check for illegal characters
	// garbageDetect is another private method in the class, and
	// works correctly.
        if(garbageDetect(data,Application.properties.getProperty("VALIDATE_"+property+"Filter")) == true) {
            throw new
NSValidation.ValidationException(Application.properties.getProperty("VALIDATE_"+property+"FilterError"));
        }

        // All done, return to sender
        return data;

}


On Sun, 5 Jan 2003, Tom Woteki wrote:

> Ed:
> It would help (me anyway) to see the code for masterStringValidator
>
> Perhaps this will help somehow: your remark below is incorrect in
> regard to RuntimeExceptions, of which NSValdation.ValidationException
> is a child. RuntimeExceptions need not be declared in a throws clause
> nor do they have to be caught anywhere. If not caught somewhere, they
> will propagate to the very top.
>
> In other words, you could simplify the signature of your
> masterStringValidator  method (and others) as follows:
>
> private String masterStringValidator( String, String, boolean );
>
> Hope this helps.
>
> Tom
>
>
> On Sunday, January 5, 2003, at 06:25 AM, Ed Powell wrote:
>
> > My understanding of exceptions is that you either need to try/catch
> > exceptions where they may occur, or define in the method's constructor
> > that it will be throwing the exception, and it gets handled 'up the
> > chain'.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Validation exceptions (From: Tom Woteki <email@hidden>)

  • Prev by Date: Re: Validation exceptions
  • Next by Date: Re: Validation exceptions
  • Previous by thread: Re: Validation exceptions
  • Next by thread: Re: Validation exceptions
  • Index(es):
    • Date
    • Thread