Results 1 to 3 of 3

Thread: Try Catch issue

  1. #1
    curtis_fraser is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default Try Catch issue

    I have a function that is called and the error messages form the catch work ok, but the reurn fails as there is a java error at the end of the try statement. I know it will be something ovious, but I can not see it. If no error is caught, then there is no error in the try block.

    Any help would be appreciated. Thx

    <!---// JavaScript Document--->

    <!--- This JavaScript Document is used for ensuring Password Standard --->
    <!--- The functions are: --->
    <!--- checkPassword() - will validate any password string --->
    //
    <!--- <INPUT type="password" name="userpassword" maxlength="20" onblur="javascript: return checkPassword(this);"> --->
    //
    <!--- You can set the maxlength to a shorter length if necessary for your application --->

    <!--- ---------------------------------------------------- --->
    <!--- Global Variables --->
    <!--- ---------------------------------------------------- --->
    var n;
    var passwordValue;
    var passwordObject;
    <!--- ------------------------------------------------------------- --->
    <!--- Function checkPassword() - will validate password string --->
    <!--- ------------------------------------------------------------- --->
    function checkPassword(formField)
    {
    var ValidNumericChars = "0123456789";
    var hasNoNumeric = true;
    var ValidUpperAlphaNumericChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var hasNoUpperAlphaNumeric = true;
    var ValidSpecialChars = "!@#$%^*()?<>[]{}\|`~_-=+?/";
    var hasNoSpecial = true;

    n=formField.name;
    passwordObject=formField;
    passwordValue=passwordObject.value;

    for(i = 0; i < ValidNumericChars.length; i++)
    {
    cCharacter = ValidNumericChars.charAt(i);
    if(passwordValue.indexOf(cCharacter) != -1)
    {hasNoNumeric = false;}
    }

    for(i = 0; i < ValidUpperAlphaNumericChars.length; i++)
    {
    Char = ValidUpperAlphaNumericChars.charAt(i);
    if(passwordValue.indexOf(Char) >= 0)
    {hasNoUpperAlphaNumeric = false;}
    }

    for(i = 0; i < ValidSpecialChars.length; i++)
    {
    Char = ValidSpecialChars.charAt(i);
    if(passwordValue.indexOf(Char) >= 0)
    {hasNoSpecial = false;}
    }

    try
    {
    if(passwordValue.length < 8){throw "SHORT";}
    if(passwordValue.length > 20){throw "LONG";}
    if(hasNoNumeric){throw "NONUMERIC";}
    if(hasNoUpperAlphaNumeric){throw "NOUPPERALPHANUMERIC";}
    if(hasNoSpecial){throw "NOSPECIAL";}
    }
    catch(error)
    {
    if(error == "SHORT"){alert("Password must be at least 8 characters in length");}
    if(error == "LONG"){alert("Password must be no more than 20 characters in length");}
    if(error == "NONUMERIC"){alert("Password must contain at least one number\n"+ValidNumericChars);}
    if(error == "NOUPPERALPHANUMERIC"){alert("Password must contain at least one upper case character\n"+ValidUpperAlphaNumericChars);}
    if(error == "NOSPECIAL"){alert("Password must contain at least one special character\n"+ValidSpecialChars);}
    setCursorPosition(passwordObject, passwordValue.length, passwordValue.length);
    return false;
    }
    }
    <!---// End--->

  2. #2
    gulapala is offline Member
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0

    Default

    The syntax of try{}catch {} is wrong.

    it should be
    <code>
    try {
    // But your code
    } catch (Exceptionclassname variable) {
    //But your errormessage here.
    }
    </code>
    Thanks & Regards, G.Rajasekhar

  3. #3
    curtis_fraser is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default syntax of try{}catch {}

    it is in this format. it is inserted into a document

    code
    try{}
    catch{}
    code

    It is ok, I've already fixed it. Passed in the name of the form and changed to set focus to field that way if an error occured. Seems to work since focus actually happens.

    Thanks anyway.

Similar Threads

  1. try catch!?
    By Joe2003 in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 07:51 PM
  2. Try Catch
    By Renegade85 in forum New To Java
    Replies: 4
    Last Post: 12-03-2007, 04:10 PM
  3. when to use try...catch
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-18-2007, 08:52 PM
  4. try...catch block
    By javaplus in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 07:53 PM
  5. Use try and catch
    By zoe in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •