check for catch try support in js

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Kypriotis
    New Member
    • Mar 2011
    • 37

    check for catch try support in js

    I have been trying to write a script as error-proofe as possible (check for DOM support, handling events according to IE/WC3 model) and the only thing I do not know how to check is the try/catch construct. For PC browsers I know above which version for each it is supported (plus I believe that its also fully supported in ECMAScript version 3 right?) but I wanna it to run and in other browsers (mobile phones etc.) where I cannot be sure what they are capable of handling and thus need a check proccedure to define if they support catch-try.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the support of try … catch is depending on the use JS engine (webkit, SpiderMonkey, V8, etc.) the last browser I know that didn’t support it was IE4!

    so I would assume that every mobile browser supports it

    Comment

    • Mike Kypriotis
      New Member
      • Mar 2011
      • 37

      #3
      Hmmm...true but still a test would be nice, never know what each browser can support, read from another thread
      "If you test the 'typeof' one of the Error classes that is supported in the version 3 of EcmaScript you can have high confidence that try-catch is also supported. The return value will be 'function'. A return value of Object means the null object, and no support. For instance:
      Code:
      if(typeof(window.TypeError)=='function'){
      go ahead and include try catch code.
      }
      "
      what do u think?
      P.S. by JS engine u are referring to the ECMAscript edition (thus the core language) supported?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        by JS engine I mean the implementation code of ECMAScript the browser vendors used.

        but my point is, if you need to check for the most basic language features, you’re overdoing things. at some point you can simply say "if even that’s not supported, my other code won’t run as well" otherwise you end up writing double and triple code.

        PS. as a demo, try to write a capturing (emulating) event handler for IE6-8.
        Last edited by Dormilich; Dec 5 '11, 06:53 PM.

        Comment

        Working...