handle exceptions

Hello there,
I know it is quite simple but I am still unable to make it work.

I want to catch exception in the scriptaculous script I have,

the script calls another functions

createNode('node1');
createNode('node2');
createNode('node3');

if there is no node2 object exist, it should simply ignore the call and not say -- node3 object not found
please advice.
regards
sam
niidmoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChetOS82Commented:
You can use try/catch blocks around each one.  Or, you could make sure that 'node2' exists before you call the function.

try {
     createNode('node2');
} catch(ex) {

}

Since 'node2' is a string, I don't know how it is actually used.  Assuming it is the ID of a HTML element do:
if (document.getElementById('node2')) {
     createNode('node2');
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
niidmoreAuthor Commented:
thanks chet, that worked for me. Yes, node2 is an ID of a HTML element in the example above.

http://xxx.xxx.xxx.26/vanillasite/carlton.asp

If you please follow the url above, the actual script works only in IE but not in Firefox. Can you please see if there is something wrong?
thanks for looking.
cheers
sam
0
ChetOS82Commented:
Modify the catch block to display the error.  It looks like the last childnode in your createEffect function is throwing the error, which causes the execution to flow the to catch block.  This skips your other two createEffect calls.

try {
...
} catch(ex) {
     alert(ex);
}
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

niidmoreAuthor Commented:
yes you are right ! could you also please let me know the fix.
much appreciate for your help.
regards
sam
0
ChetOS82Commented:
No, I am not sure what the problem is exactly.  I suggest that you download Firebug for Firefox and step through the code checking it with the debugger.
0
niidmoreAuthor Commented:
ok thanks for your help though
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.