jslint and conditional catch blocks

Discussion in 'Javascript' started by Simon Oberhammer, Dec 10, 2008.

  1. not sure if this is rhino specific, but in accordance to the mozilla-
    docs [1] we have a lot of the following in our code. and jslint
    doesn't like it:

    try {
    // function could throw exceptions
    } catch (e if e == "InvalidNameException") {

    } catch (e....)

    jslint says:

    line 50 Expected ')' and instead saw 'if'.
    } catch (e if e instanceof Exception) {

    line 50 Expected '{' and instead saw 'e'.
    } catch (e if e instanceof Exception) {

    line 50 Expected an assignment or function call and instead saw an
    expression.
    } catch (e if e instanceof Exception) {


    not sure if i should fix jslint or our code...

    greetings
    simon
     
    Simon Oberhammer, Dec 10, 2008
    #1
    1. Advertising

  2. Simon  Oberhammer

    Henry Guest

    On Dec 10, 4:22 pm, Simon Oberhammer wrote:
    > not sure if this is rhino specific, but in accordance to
    > the mozilla- docs [1] we have a lot of the following in
    > our code. and jslint doesn't like it:
    >
    > try {
    > // function could throw exceptions
    >
    > } catch (e if e == "InvalidNameException") {


    This is a JavaScript(tm) extension, conditional catch is not part of
    ECMA 262 (and will not even be part of the next (3.1) version, which
    is a pity as without them the try-catch system is javascript is not
    particularly useful.

    <snip>
    > not sure if i should fix jslint or our code...


    Jslint is checking against ECMA 262 (3rd Ed.) and your code is outside
    of ECMAScript, so neither are wrong as such, just incompatible.
     
    Henry, Dec 10, 2008
    #2
    1. Advertising

  3. On Dec 10, 11:22 am, Simon Oberhammer <>
    wrote:
    > try {
    > // function could throw exceptions
    >
    > } catch (e if e == "InvalidNameException") {
    > } catch (e....)


    Conditional catch is a compile error, Opera on KDE.
     
    Martin Rinehart, Dec 11, 2008
    #3
  4. Simon Oberhammer wrote:
    > not sure if this is rhino specific, but in accordance to the mozilla-
    > docs [1] we have a lot of the following in our code. and jslint
    > doesn't like it:
    >
    > try {
    > // function could throw exceptions
    > } catch (e if e == "InvalidNameException") {


    That is either not the code that you used, or the messages that you posted
    below are not the ones that you received, or you posted only the irrelevant
    parts of your code. Either way, please make it better next time.

    In general, this code doesn't make much sense anyway. The string
    representation of an Error object is specified to be implementation defined,
    and if `e' is a user-defined object instead, its string representation would
    have to be `InvalidNameException' for this to work. Probably you were
    looking for

    try
    {
    // code that can throw a user-defined InvalidNameException object
    }
    catch (e if e instanceof InvalidNameException)
    {
    // ...
    }

    instead.

    > } catch (e....)
    >
    > jslint says:
    >
    > line 50 Expected ')' and instead saw 'if'.
    > } catch (e if e instanceof Exception) {


    jslint does not seem to know about proprietary extensions to the ECMAScript
    Language Specification such as this feature, supported only in Mozilla.org
    JavaScript[tm](R) since version 1.5 (since Firefox 1.0 and friends).

    <http://PointedEars.de/es-matrix/#try>

    I would consider this a(nother) bug in jslint since there can be no doubt
    about what Rhino is, and jslint has an explicit "Rhino option" that does
    not help here when it should (see below).

    > not sure if i should fix jslint or our code...


    Since the code is supposed to run by Rhino, which is the Java implementation
    of the JavaScript[tm](R) script engine (as compared to SpiderMonkey, the C
    implementation of that engine, which is used in many Mozilla.org end-user
    software, including Firefox), you can leave the code as it is.

    However, I recommend you use the `instanceof' operator in favor of `==' in
    all `catch' statements.

    Sounds like a good idea if you fixed jslint so that it worked properly with
    Rhino and sent Douglas Crockford a patch (if you wanted to). But he could
    be faster than you ;-)


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Dec 11, 2008
    #4
  5. Martin Rinehart wrote:
    > Simon Oberhammer wrote:
    >> try {
    >> // function could throw exceptions
    >>
    >> } catch (e if e == "InvalidNameException") {
    >> } catch (e....)

    >
    > Conditional catch is a compile error, Opera on KDE.


    As expected. But we are talking about Rhino code here.


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
     
    Thomas 'PointedEars' Lahn, Dec 11, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. matt
    Replies:
    1
    Views:
    284
    George Ogata
    Aug 6, 2004
  2. Steven Taylor
    Replies:
    9
    Views:
    270
    Brian Candler
    Apr 27, 2009
  3. Douglas Crockford

    JSLINT

    Douglas Crockford, Aug 27, 2004, in forum: Javascript
    Replies:
    0
    Views:
    98
    Douglas Crockford
    Aug 27, 2004
  4. Replies:
    44
    Views:
    362
    John G Harris
    May 25, 2006
  5. Andrew Poulos

    delete ax object and JSLint

    Andrew Poulos, May 31, 2009, in forum: Javascript
    Replies:
    10
    Views:
    211
Loading...

Share This Page