Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 01:16 AM
Member
 
Join Date: Dec 2007
Posts: 2
curtis_fraser is on a distinguished road
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--->
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-13-2007, 01:48 PM
Member
 
Join Date: Dec 2007
Posts: 11
gulapala is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-14-2007, 12:04 AM
Member
 
Join Date: Dec 2007
Posts: 2
curtis_fraser is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
try catch!? Joe2003 Advanced Java 2 01-28-2008 08:51 PM
Try Catch Renegade85 New To Java 4 12-03-2007 05:10 PM
when to use try...catch javaplus New To Java 2 11-18-2007 09:52 PM
try...catch block javaplus New To Java 3 11-06-2007 08:53 PM
Use try and catch zoe New To Java 2 07-25-2007 08:50 PM


All times are GMT +3. The time now is 02:23 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org