473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sintax for try and except istruction

is there an istruction like the
try .....
except.....
Jul 23 '05 #1
12 1720
VK
> try .....
except.....


You ment the clause:
try {} catch (e) {} finally{}

Yes, it has been relatively recently added to both JavaScript and JScript.
Never seen it in use yet though in actual scripts. Either no much use, or
some implementation errors, or I don't know.
Would be great to get some feed-back from who ever used it.
Jul 23 '05 #2
On Sat, 09 Oct 2004 10:44:35 GMT, SAN CAZIANO <al**********@tin.it> wrote:
is there an istruction like the
try .....
except.....


var e;

try {

// Execute exception-causing code here

} catch(e) {

// e represents the exception thrown

} finally {

// Code always executed, whether an exception was thrown or not

}

A try statement doesn't require both of the catch and finally clauses, but
at least one of them must be included.

This is a fairly recent addition to the language. Browsers like NN4 will
error when encountering these keywords as they were reserved during that
time. IE5, Netscape 6 and Mozilla will support try..catch. I don't know
when Opera began support.

Are you certain you need to use these statements?

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
One reason why it is used and in fact I use it for this reason.

When your page loads you cannot refer to an element's id until the element has actually been created. Now
consider you have made a page that is actually a template. The page dynamically loads an image. If the image is
large the <div id="oLImage...> loads but if the image is small <div id="oSImage ...> loads. You don't know
which image is going to be requested and therefore which div will be made. One or the other but not both will
be made. Here's the solution:

try{
// do something with element id='oLImage'
}
catch{
//do something with element id='oSImage'
}

No script errors on the page but in fact an error does occur when <div id='oSImage'....> (the image is
small) results which goes to the catch().

--
George Hester
__________________________________
"VK" <sc**********@yahoo.com> wrote in message news:41*********************@news.freenet.de...
try .....
except.....


You ment the clause:
try {} catch (e) {} finally{}

Yes, it has been relatively recently added to both JavaScript and JScript.
Never seen it in use yet though in actual scripts. Either no much use, or
some implementation errors, or I don't know.
Would be great to get some feed-back from who ever used it.

Jul 23 '05 #4
I'm sorry it should be:

try{
// do something with element id='oLImage'
}
catch(e){
//do something with element id='oSImage'
}

You can use the e to get the actual error message if you want:

try{
// do something with element id='oLImage'
}
catch(e){
var errMsg = 'The error was:\n\n';
errMsg += 'Error number: '+(e.number & 0xFFFF);
errMsg += '\n'+e.description;
//do something with element id='oSImage'
// alert(errMsg);
}

--
George Hester
__________________________________
"George Hester" <he********@hotmail.com> wrote in message news:32*********************@twister.nyroc.rr.com. ..
One reason why it is used and in fact I use it for this reason.

When your page loads you cannot refer to an element's id until the element has actually been created. Now
consider you have made a page that is actually a template. The page dynamically loads an image. If the image is
large the <div id="oLImage...> loads but if the image is small <div id="oSImage ...> loads. You don't know
which image is going to be requested and therefore which div will be made. One or the other but not both will
be made. Here's the solution:

try{
// do something with element id='oLImage'
}
catch{
//do something with element id='oSImage'
}

No script errors on the page but in fact an error does occur when <div id='oSImage'....> (the image is
small) results which goes to the catch().

--
George Hester
__________________________________
"VK" <sc**********@yahoo.com> wrote in message news:41*********************@news.freenet.de...
try .....
except.....


You ment the clause:
try {} catch (e) {} finally{}

Yes, it has been relatively recently added to both JavaScript and JScript.
Never seen it in use yet though in actual scripts. Either no much use, or
some implementation errors, or I don't know.
Would be great to get some feed-back from who ever used it.

Jul 23 '05 #5
On Sat, 09 Oct 2004 13:51:59 GMT, George Hester <he********@hotmail.com>
wrote:

[snip]
The page dynamically loads an image. If the image is large the <div
id="oLImage...> loads but if the image is small
<div id="oSImage ...> loads. You don't know which image is going to be
requested and therefore which div will be made.
[snip]
No script errors on the page but in fact an error does occur when <div
id='oSImage'....> (the image is small) results which goes to the
catch().


Assuming I understand you correctly, that isn't a valid reason to use
try..catch. Assuming you can't generate code that is relevant to the
generated mark-up, test. If the element doesn't exist, you won't get a
valid object reference. You simply need to test for that and act
accordingly. But as I said, generating the correct script for the current
mark-up is surely the sensible thing to do.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message news:opsflw0iiix13kvk@atlantis...
On Sat, 09 Oct 2004 13:51:59 GMT, George Hester <he********@hotmail.com>
wrote:

[snip]
The page dynamically loads an image. If the image is large the <div
id="oLImage...> loads but if the image is small
<div id="oSImage ...> loads. You don't know which image is going to be
requested and therefore which div will be made.
[snip]
No script errors on the page but in fact an error does occur when <div
id='oSImage'....> (the image is small) results which goes to the
catch().


Assuming I understand you correctly, that isn't a valid reason to use
try..catch. Assuming you can't generate code that is relevant to the
generated mark-up, test. If the element doesn't exist, you won't get a
valid object reference. You simply need to test for that and act


the test is try() the act accordingly is catch(e){}
accordingly. But as I said, generating the correct script for the current
mark-up is surely the sensible thing to do.

Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


What's the problem with that?

George Hester
__________________________________

Jul 23 '05 #7
On Sat, 09 Oct 2004 14:50:32 GMT, George Hester <he********@hotmail.com>
wrote:

[snip]
Assuming I understand you correctly, that isn't a valid reason to use
try..catch. Assuming you can't generate code that is relevant to the
generated mark-up, test. If the element doesn't exist, you won't get a
valid object reference. You simply need to test for that and act
[accordingly.]
the test is try() the act accordingly is catch(e){}


[snip]
What's the problem with that?


It's unnecessary?

If you have an object reference,

if(objRef) {

will check if it's non-null. If at the time of that test, objRef
references one DIV that doesn't exist, the reference will be null and the
expression will evaluate as false.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message news:opsfl01bhnx13kvk@atlantis...
On Sat, 09 Oct 2004 14:50:32 GMT, George Hester <he********@hotmail.com>
wrote:

[snip]
Assuming I understand you correctly, that isn't a valid reason to use
try..catch. Assuming you can't generate code that is relevant to the
generated mark-up, test. If the element doesn't exist, you won't get a
valid object reference. You simply need to test for that and act
[accordingly.]


the test is try() the act accordingly is catch(e){}


[snip]
What's the problem with that?


It's unnecessary?

If you have an object reference,

if(objRef) {

will check if it's non-null. If at the time of that test, objRef
references one DIV that doesn't exist, the reference will be null and the
expression will evaluate as false.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


six of one 1/2 dozen of the other

I never said it was necessary just sufficient for browsers which support it.

George Hester
__________________________________
Jul 23 '05 #9
George Hester wrote:
Michael Winter wrote:
George Hester wrote: <snip>
No script errors on the page but in fact an error does occur
when <div id='oSImage'....> (the image is small) results
which goes to the catch().


Assuming I understand you correctly, that isn't a valid reason
to use try..catch. Assuming you can't generate code that is
relevant to the generated mark-up, test. If the element doesn't
exist, you won't get a valid object reference. You simply
need to test for that and act


the test is try() the act accordingly is catch(e){}

<snip>

try-catch-finally is designed to handle exceptions; exceptions being
conditions outside of the ability of normal code to detect and control.
Their use in place of normal program flow control logic is
inappropriate, relatively inefficient (lots of overheads in scope chain
modification), incorrect, and should be broadly categorised as a hack.

It doesn't surprise me that you use try-catch for flow control, but as
usual you should not inflict your nonsense on others.

Richard.
Jul 23 '05 #10

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:ck*******************@news.demon.co.uk...
George Hester wrote:
Michael Winter wrote:
George Hester wrote: <snip> No script errors on the page but in fact an error does occur
when <div id='oSImage'....> (the image is small) results
which goes to the catch().

Assuming I understand you correctly, that isn't a valid reason
to use try..catch. Assuming you can't generate code that is
relevant to the generated mark-up, test. If the element doesn't
exist, you won't get a valid object reference. You simply
need to test for that and act


the test is try() the act accordingly is catch(e){}

<snip>

try-catch-finally is designed to handle exceptions; exceptions being
conditions outside of the ability of normal code to detect and control.
Their use in place of normal program flow control logic is
inappropriate, relatively inefficient (lots of overheads in scope chain
modification), incorrect, and should be broadly categorised as a hack.

It doesn't surprise me that you use try-catch for flow control, but as
usual you should not inflict your nonsense on others.

Richard.



Why you Richard are determined to always patronize me whenever you find my posts.
Why don't you just block my posts? Pleasre put me on your ban list then I won't have to read your
crap. You don't like my crap so ban me. PLEASE!!!

As for your comment about the try catch well taken and is exactly why I used it. How you saw
it done is yes unnecessary but so goddamn what.

--
George Hester
__________________________________
Jul 23 '05 #11
George Hester wrote:
Richard Cornford wrote:
George Hester wrote: <snip>
the test is try() the act accordingly is catch(e){} <snip>
try-catch-finally is designed to handle exceptions; exceptions
being conditions outside of the ability of normal code to
detect and control. Their use in place of normal program flow
control logic is inappropriate, relatively inefficient (lots
of overheads in scope chain modification), incorrect, and
should be broadly categorised as a hack.

It doesn't surprise me that you use try-catch for flow control,
but as usual you should not inflict your nonsense on others.


Why you Richard are determined to always patronize me whenever
you find my posts.


I am determined that the universally (and often uniquely) bad advice you
give out should not exist in a public arena without an appropriate
indication of its true status.
Why don't you just block my posts? Pleasre put me on your
ban list then I won't have to read your crap.
If you don't want to read my "crap" you can killfile me. You are in
complete control of your ability to do that, and I have no intention of
doing what you suggest. To date I have never killfiled anyone (I have
come close a couple of times).
You don't like my crap so ban me. PLEASE!!!
If I could be confident that you would not attempt to inflict your crap
on innocent third parities then killfiling you might be the simplest
option. But as you insist on posting responses to questions it will
remain necessary to be able to advise the recipients of your "answers"
that advice originating with George Hester is best regarded as
intrinsically wrong and that doing anything else would probably be a
better alternative.
As for your comment about the try catch well taken and
is exactly why I used it.
Yes, your clearly use try-catch for program flow control.
How you saw it done is yes unnecessary but so goddamn what.


It is a manifestation of the difference between programming and what you
do.

Richard.
Jul 23 '05 #12
On Sat, 09 Oct 2004 10:44:35 GMT, in comp.lang.javascript "SAN
CAZIANO" <al**********@tin.it> wrote:
| is there an istruction like the
| try .....
| except.....


Other people have pointed out the syntax of try/catch.
How are you planning to use this, client-side or server-side?

While I believe there is little use with client-side code there is
good reasons to have this server-side (database updates, file
read/write, file transfers etc).

---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Erlend Fuglum | last post by:
Hi everyone, I'm having some trouble sorting lists. I suspect this might have something to do with locale settings and/or character encoding/unicode. Consider the following example, text...
3
by: George Young | last post by:
I have a bunch of blanket "except:" clauses like: class DatabaseError(StandardError): pass class OperationalError(StandardError): pass try: stuff except _pg.error, msg: raise...
7
by: Robert Brewer | last post by:
Alex Martelli wrote in another thread: > One sign that somebody has moved from "Python newbie" to "good Python > programmer" is exactly the moment they realize why it's wrong to code: > > ...
0
by: John J. Lee | last post by:
Bare "except:", with no exception specified, is nasty because it can easily hide bugs. There is a case where it seemed useful to me in the past. Now it seems like a bad idea to me (but I think...
2
by: Thorsten Kampe | last post by:
What is the best way to except two errors, when the except handling in both cases is the same? "except:" would just except every error and not just those I want. except Attribute error:...
1
by: simon | last post by:
This works in VB: <td <%# myFunction(DataBinder.Eval(Container.DataItem,"column1"))%>> but in C# doesn't. What is the right sintax to include some text between the html tag in C#? I can't...
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
35
by: Arnaud Delobelle | last post by:
Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x),...
7
by: InuY4sha | last post by:
Hi all :) sorry.. I know this is a very mean question but I can't get the following couple of lines: static int dev_init(struct net_device *dev); struct net_device my_device = { init: dev_init,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.