[Javascript] Try and Catch Question
MEM
talofo at gmail.com
Tue Mar 3 10:40:14 CST 2009
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
More information about the Javascript
mailing list