[Javascript] Javascript Digest, Vol 19, Issue 2

shashanka n shashankan.10 at gmail.com
Wed Mar 4 00:22:50 CST 2009


On Tue, Mar 3, 2009 at 11:30 PM, <javascript-request at lists.evolt.org> wrote:

> Send Javascript mailing list submissions to
>        javascript at lists.evolt.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.evolt.org/mailman/listinfo/javascript
> or, via email, send a message with subject or body 'help' to
>        javascript-request at lists.evolt.org
>
> You can reach the person managing the list at
>        javascript-owner at lists.evolt.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Javascript digest..."
>
> Today's Topics:
>
>   1. Re: Try and Catch Question (Troy III Ajnej)
>   2. Re: Try and Catch Question (MEM)
>
>
> ---------- Forwarded message ----------
> From: Troy III Ajnej <trojani2000 at hotmail.com>
> To: <javascript at lists.evolt.org>
> Date: Tue, 3 Mar 2009 15:44:04 +0000
> Subject: Re: [Javascript] Try and Catch Question
>
> Hello MEM,
>
>
>
> > Well, I have seen also with ‘err’ etc, so I presume the point is to have
>
> > only something that represents the name error. But, what for? I mean,
>
> > normally in this kind of statements I never see that ‘e’ or ‘err’ being
> used
>
> > for nothing, I see no e=”ups error” or something. So, what is that e for?
>
>
>
> The "catch(whatever)" is obviously a function-call that depends on
>
> the coder input for it to become useful. If you catch the error, you
>
> are certainly aiming to get the cause, and since there was no way
>
> of knowing the argument-name of this function for all the browsers
>
> that wrote it independently, it was wisely decided to let this arg
>
> be named by the coder so you can extract at least some poor laconic
>
> info about the expected error using your own bite.
>
> Anyway the catch() function will fail to execute if this arg is missing.
>
> It will most probably yield "null", so the error will slip off the catch
> and
>
> the suppression will fail.
>
>
>
> > Why do we need the ‘e’ ?
>
> Aside the fact that omitting "e" will cause the error capture to fail
> suppress
>
> the expected error, we need it to watch for our runtime errors like in:
>
>
>
> try {
>
>  thisUndeclaredFunction()
>
>  }
>
>
>
> catch(thatError){
>
>  alert(thatError.message)
>
>  }
>
>
>
> [As you can see we're not using "e" or "err"]
>
>
>
> In this example our alert(thatError.message) request will report:
>
> "Object expected" or if we alert(thatError.name) we'll get "typeError"
>
> meaning: error in expected variable type has occurred, which is caused
>
> by "thisUndeclaredFunction()" name variable call.
>
>
>
> It is completely unreasonable to call "document.getElementById()"
>
> if you are not aiming to really catch some particular element in your var.
>
> Therefore using the catch() method to simply suppress some error
>
> you don't care to know what, might well be called a misuse, since
>
> suppressing errors anonymously can be achieved globally by simply returning
>
> "true" for the "onerror" event.
>
>
>
> Regards.
>
>
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>                                      Troy III
>                         progressive art enterprise
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> > From: talofo at gmail.com
> > To: javascript at lists.evolt.org
> > Date: Mon, 2 Mar 2009 12:16:02 +0000
> > Subject: [Javascript] Try and Catch Question
> >
> > Hi all, this is my first post, (so if anything is not right in the way I
> > post, please let me know).
> >
> >
> >
> >
> >
> > When we use a try catch statement like this:
> >
> > try {
> >
> >
> >
> > } catch (e) {
> >
> >
> >
> > }
> >
> >
> >
> > Why do we need the ‘e’ ?
> >
> >
> >
> > Well, I have seen also with ‘err’ etc, so I presume the point is to have
> > only something that represents the name error. But, what for? I mean,
> > normally in this kind of statements I never see that ‘e’ or ‘err’ being
> used
> > for nothing, I see no e=”ups error” or something. So, what is that e for?
> >
> >
> >
> >
> >
> > Thanks a lot,
> >
> > Márcio
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at lists.evolt.org
> > http://lists.evolt.org/mailman/listinfo/javascript
>
> _________________________________________________________________
> Windows Live™ Groups: Create an online spot for your favorite groups to
> meet.
> http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009
>
>
> ---------- Forwarded message ----------
> From: "MEM" <talofo at gmail.com>
> To: "'JavaScript List'" <javascript at lists.evolt.org>
> Date: Tue, 3 Mar 2009 16:40:14 -0000
> Subject: Re: [Javascript] Try and Catch Question
> THANK A LOT for all the replys. :) I'm more then glad!
>
> Here I go digging deep into javascript again! :)
>
> Thanks a million, really. Hope I can count on the mailing list for more
> newbie questions, because I really want to properly LEARN javascript.
> And one day maybe I will be on your side.
>
> Regards,
> Márcio
>
>
> -----Original Message-----
> From: javascript-bounces at lists.evolt.org
> [mailto:javascript-bounces at lists.evolt.org] On Behalf Of Troy III Ajnej
> Sent: terça-feira, 3 de Março de 2009 15:44
> To: javascript at lists.evolt.org
> Subject: Re: [Javascript] Try and Catch Question
>
>
> Hello MEM,
>
>
>
> > Well, I have seen also with ‘err’ etc, so I presume the point is to have
>
> > only something that represents the name error. But, what for? I mean,
>
> > normally in this kind of statements I never see that ‘e’ or ‘err’ being
> used
>
> > for nothing, I see no e=”ups error” or something. So, what is that e for?
>
>
>
> The "catch(whatever)" is obviously a function-call that depends on
>
> the coder input for it to become useful. If you catch the error, you
>
> are certainly aiming to get the cause, and since there was no way
>
> of knowing the argument-name of this function for all the browsers
>
> that wrote it independently, it was wisely decided to let this arg
>
> be named by the coder so you can extract at least some poor laconic
>
> info about the expected error using your own bite.
>
> Anyway the catch() function will fail to execute if this arg is missing.
>
> It will most probably yield "null", so the error will slip off the catch
> and
>
> the suppression will fail.
>
>
>
> > Why do we need the ‘e’ ?
>
> Aside the fact that omitting "e" will cause the error capture to fail
> suppress
>
> the expected error, we need it to watch for our runtime errors like in:
>
>
>
> try {
>
>  thisUndeclaredFunction()
>
>  }
>
>
>
> catch(thatError){
>
>  alert(thatError.message)
>
>  }
>
>
>
> [As you can see we're not using "e" or "err"]
>
>
>
> In this example our alert(thatError.message) request will report:
>
> "Object expected" or if we alert(thatError.name) we'll get "typeError"
>
> meaning: error in expected variable type has occurred, which is caused
>
> by "thisUndeclaredFunction()" name variable call.
>
>
>
> It is completely unreasonable to call "document.getElementById()"
>
> if you are not aiming to really catch some particular element in your var.
>
> Therefore using the catch() method to simply suppress some error
>
> you don't care to know what, might well be called a misuse, since
>
> suppressing errors anonymously can be achieved globally by simply returning
>
> "true" for the "onerror" event.
>
>
>
> Regards.
>
>
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>                                      Troy III
>                         progressive art enterprise
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> > From: talofo at gmail.com
> > To: javascript at lists.evolt.org
> > Date: Mon, 2 Mar 2009 12:16:02 +0000
> > Subject: [Javascript] Try and Catch Question
> >
> > Hi all, this is my first post, (so if anything is not right in the way I
> > post, please let me know).
> >
> >
> >
> >
> >
> > When we use a try catch statement like this:
> >
> > try {
> >
> >
> >
> > } catch (e) {
> >
> >
> >
> > }
> >
> >
> >
> > Why do we need the ‘e’ ?
> >
> >
> >
> > Well, I have seen also with ‘err’ etc, so I presume the point is to have
> > only something that represents the name error. But, what for? I mean,
> > normally in this kind of statements I never see that ‘e’ or ‘err’ being
> used
> > for nothing, I see no e=”ups error” or something. So, what is that e for?
> >
> >
> >
> >
> >
> > Thanks a lot,
> >
> > Márcio
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at lists.evolt.org
> > http://lists.evolt.org/mailman/listinfo/javascript
>
> _________________________________________________________________
> Windows Live™ Groups: Create an online spot for your favorite groups to
> meet.
> http://windowslive.com/online/groups?ocid=TXT_TAGLM_WL_groups_032009
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
>

Um, though this might seem off topic, i would like to point out that the try
catch statements should not be used in a very generic way. Such as this

try{
//MAJOR chunk of your code
}
catch(err)
{
   //Do something to rectify this...
}

I would recommend this rather be used for small chunks of your code rather
than put a majority of your code in the try section...

-- 
- Warm regards

Shashanka N



More information about the Javascript mailing list