473,699 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finally in IE


Hello,

I've been looking in the archives but found no interesting answer to
my problem.
I was wondering why the following code does not work in IE 5; I'd
expect an alert showing 'In finally!', but I keep getting an IE error
dialog..
Has anyone any idea why that is so?
(the code works in mozilla :) )

Best regards,
Arnaud
----snip----
<html>
<head>
<title>Finally? !</title>
</head>
<body>
<script>
try {

throw "Error!!";

} finally {

alert ("In finally!");
}
</script>
</body>
</html>
----snip----

Dec 6 '05 #1
3 4573
"Arnaud Diederen (aundro)" <ad@remove.the. a.in.ionicsoft. com> wrote in
message news:87******** ****@paddy.ioni csoft.com...

Hello,

I've been looking in the archives but found no interesting answer to
my problem.
I was wondering why the following code does not work in IE 5; I'd
expect an alert showing 'In finally!', but I keep getting an IE error
dialog..
Has anyone any idea why that is so?


This any help? I tried your code and got "Exception thrown and not caught"
so I Googled on that phrase and found this link.

http://msdn.microsoft.com/library/de...nnotcaught.asp
Dec 6 '05 #2
"Danny@Kend al" <da***@removeth isbit.ghpkendal .co.uk> writes:

This any help? I tried your code and got "Exception thrown and not caught"
so I Googled on that phrase and found this link.

http://msdn.microsoft.com/library/de...nnotcaught.asp


Thank you for the link, it made me try the following:

----snip----
try {
try {

throw "Error!!";

} finally {

document.write ("finally executed");
}

} catch (e) {

alert (e);

} finally {

alert ('last finally');
}
----snip----

... and it works as expected. I must admit I don't really understand
what makes it work, while the other example fail.

Maybe a problem of "using-try/catch/finally-blocks-too-early-before-
the-page-is-fully-loaded" or something..

Thank you for the pointer! :)

Best regards,
Arnaud
--
Arnaud DIEDEREN
Software Developer
IONIC Software
Rue de Wallonie, 18 - 4460 Grace-Hollogne - Belgium
Tel: +32.4.3640364 - Fax: +32.4.2534737
mailto:ad@ionic soft.com
http://www.ionicsoft.com
Dec 6 '05 #3
VK

Arnaud Diederen aundro wrote:
try {
try {

throw "Error!!";

} finally {

document.write ("finally executed");
}

} catch (e) {

alert (e);

} finally {

alert ('last finally');
}
----snip----

.. and it works as expected. I must admit I don't really understand
what makes it work, while the other example fail.


throw new Error("My error") is not like some alert("An error happened")
;-)

If a block throws an error it says: "An oops happened which I cannot /
don't want to deal with. Anyone smarter than I am?"

Usually the "smarter partner" has to be in the catch block right here
or in a catch block somewhere higher. If no smart guy (appropriate
catch block) found then the program executes [finally] block and
aborts. Therefore the originally posted testcase is not from the real
life - it is a curiosity puzzle "what if?" In the real programming you
never throw exceptions "into space". There always *must* be a catch
block provided somewhere. Still even a pure curiosity is a good thing
;-) so here how does it work (this is taken from C# but similar to all
C-based languages):

1) If an exception is thrown, each catch clause is inspected in turn
for a type to which the exception can be assigned; be sure to order
them from most specific to least specific
2) when a match is found, the exception object is assigned to the
identifier and the catch statements are executed
3) if no matching catch clause is found, the exception percolates up to
any outer try block that may handle it
4) if a finally clause is included, it's statements are executed after
all other try-catch processing is complete
5) the [finally] clause executes wether or not an exception is thrown
or a break or continue are encountered
Note: If a catch clause invokes System.exit() the finally clause
WILL NOT execute.
So in the case like

try {
throw new Error('My error');
}
funally {
alert('Booh!');
}

Firefox considers your <script> block as self-enclosed system. After
reaching the top (<script> borders) and failing to find an appropriate
catch block, it returns control to [finally] and aborts right after.

Internet Explorer considers your <script> as a part of the global
JScript context. After reaching the top (<script> borders) and failing
to find an appropriate catch block, it forwards control further to the
JScript interpreter in hope that that one knows what to do with it.
Naturally JScript interpreter has not such exception registered in its
table and it does what it was instructed to do in such cases: it aborts
the execution. Therefore the control never gets a chance to come back
to [finally].

Hope it helps.

Dec 6 '05 #4

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

Similar topics

4
2947
by: Brian Alexander | last post by:
Hello; I'm curious to know how people preserve exceptions that arise in a try ... finally block. Consider this example: try: getResource() doSomething() finally: alwaysFreeResource()
26
2514
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise Error # Error is subclass of Exception
16
7941
by: Ken | last post by:
What is the purpose of a finally block in try-catch- finally? I am confused because, if I am reading the definition correctly, this block seems unnecessary. Consider the following from the Visual Studio documentation. In the first foo(), the statement in the finally block will execute even though there is an exception in the try block. In the second foo(), I took the statement out of the finally block but it should still execute since it...
16
10082
by: Bill | last post by:
Say I have a childThread currently is running a finally block to cleanup external resources. At the same time the main thread calls childThread.Abort(). The question is: when the ThreadAbortException is thrown, does the childThread finish the remaining code in the finally block?
3
4825
by: Brian | last post by:
Is it possible to have more than one try/catch/finally block within a method? Also, if the code never enters the try block of code, is the finally block executed? I have a try block in a branch of a switch statement and I only want the finally to execute if the branch of the switch statement is executed.
8
2733
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block? (ie, forget the finally block and just end the try/catch and put the code after the try/catch block). Or does the "finally" construct add some additional functionality?
16
2082
by: Chris | last post by:
Hi, regarding exception-handling : why put code in a 'finally' block, and not just after a 'catch'-block --> Example using 'finally ' : try { OpenFile();
7
1720
by: Sean Kirkpatrick | last post by:
I got caught with my pants down the other day when trying to explain Try...Catch...Finally and things didn't work as I had assumed. Perhaps someone can explain to me the purpose of Finally. I've looked at several texts that I have and none of them address this specific point. If I call some method that throws an exception in my routine Foo, sub foo call bar <- throws an exception do something else <- never get here
32
6118
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I understand Finally runs whether an error was caught or not, I haven't found a use for finally yet.
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.