Results 1 to 8 of 8

Thread: javascript error checking

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870

    javascript error checking

    hi,

    is it possible to do error checking with javascript?

    If an error shows up, I want it to continue running the code, but perhaps miss out a bit.

    Thanks
    Nick

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    If there is a syntax error, there is nothing you can do, the script will die. If you want to make sure you avoid errors, you can build your scripts to do their error handling. Always make sure an object has been instantiated before you call a property/method. Use conditionals to confirm assignments, always double check user input, yadda yadda.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    Error: 'undefined' is null or not an object

    - is the error i get. I know why i get it, and there is no easy fix for it! Is there a way i can miss it?

    Cheers

  4. #4
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Can't you do something to do with the try, catch and throw keywords?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    to be honest i don't know what they are.

    I am not the best javascript programmer in the world you see!!!

  6. #6
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    You error sounds like you are trying to access a variable that is not defined. Either you haven't declared it and assigned a value, or you think you have instantiated an object that you haven't.

    The throw/catch stuff would work great.

    Try the links in my sig.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  7. #7
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    I like the try-catch-finally error handling. I use it in Java, but didn't know that JavaScript had it too.

    You can also test to see if a variable is defined or not. I think it's:

    if (variable) {}

    Which will only be true if the variable exists or is defined. Also, you can further check:

    if (variable != null) {}

    to verify if something is defined, yet is null.

    With these, you can test out before it errors out.

    cudabean

  8. #8
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Can you post you code so we can see where the problem is?

Posting Permissions

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



Click Here to Expand Forum to Full Width