Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30605

Re: try ... catch for a specific error ?

Newsgroups comp.lang.javascript
Subject Re: try ... catch for a specific error ?
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <574fe5c6$0$5901$e4fe514c@news.xs4all.nl>
Date 2016-06-02 11:21 +0200
Message-ID <XnsA61B73815550eejj99@194.109.6.166> (permalink)

Show all headers | View raw


"R.Wieser" <address@not.available> wrote on 02 Jun 2016 in 
comp.lang.javascript:

> Hello all,
> 
> I'm executing a command which can return a specific error constant
> indicating the item is not found.  I would like to catch that error alone
> (returning an empty string instead of failing), and have the system handle
> all others.
> 
> Two seperate questions:
> 1) Can I tell the "catch" to only do so on (a) specific error(s) ?
> 
> if not than:
> 
> 2) how can I ...
> 
> a) compare the error constant against the "err" object (it does not seem 
to
> expose it)
> 
> b) tell the system to handle/continue with the errors I have not handled
> myself.

Try..catch seems to me for "inspecific" errors,
not for an "executed command" [what is that, btw?] 
returning a specific value hat you interpret as an error-vallue.

Why not just:

var myErrorConstant = myExecutedCommand();

if (myErrorConstant != 0)
    console.log('myErrorConstant=' + myErrorConstant);

or

var myErrorConstant = myExecutedCommand();

if (myErrorConstant != 0)
    alert('myErrorConstant=' + myErrorConstant);



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-02 09:54 +0200
  Re: try ... catch for a specific error ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-02 11:21 +0200
    Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-02 12:18 +0200
      Re: try ... catch for a specific error ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-02 13:22 +0200
  Re: try ... catch for a specific error ? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-02 12:38 +0200
    Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-02 14:32 +0200
      Re: try ... catch for a specific error ? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-02 14:40 +0200
        Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-02 15:40 +0200
          Re: try ... catch for a specific error ? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-02 16:03 +0200
            Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-02 16:23 +0200
              Re: try ... catch for a specific error ? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-02 16:43 +0200
              Re: try ... catch for a specific error ? Tim Streater <timstreater@greenbee.net> - 2016-06-02 20:42 +0100
                Re: try ... catch for a specific error ? Tim Streater <timstreater@greenbee.net> - 2016-06-02 20:44 +0100
      Re: try ... catch for a specific error ? JJ <jj4public@vfemail.net> - 2016-06-02 20:24 +0700
        Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-02 16:35 +0200
          Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-03 10:50 +0200
            Re: try ... catch for a specific error ? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-03 17:35 +0200
            Re: try ... catch for a specific error ? "R.Wieser" <address@not.available> - 2016-06-03 22:25 +0200
              Re: try ... catch for a specific error ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-06-03 23:55 +0200

csiph-web