Connecting Tech Pros Worldwide Help | Site Map

Finally in IE

  #1  
Old December 6th, 2005, 11:05 AM
Arnaud Diederen
Guest
 
Posts: n/a

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----

  #2  
Old December 6th, 2005, 11:35 AM
Danny@Kendal
Guest
 
Posts: n/a

re: Finally in IE


"Arnaud Diederen (aundro)" <ad@remove.the.a.in.ionicsoft.com> wrote in
message news:87vey2zecj.fsf@paddy.ionicsoft.com...[color=blue]
>
> 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?[/color]

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


  #3  
Old December 6th, 2005, 02:45 PM
Arnaud Diederen
Guest
 
Posts: n/a

re: Finally in IE


"Danny@Kendal" <danny@removethisbit.ghpkendal.co.uk> writes:
[color=blue]
>
> 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[/color]

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@ionicsoft.com
http://www.ionicsoft.com
  #4  
Old December 6th, 2005, 04:45 PM
VK
Guest
 
Posts: n/a

re: Finally in IE



Arnaud Diederen aundro wrote:[color=blue]
> 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.[/color]

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.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to display inline navigation next to an img using css? works in IE not mozilla Jannette answers 3 September 8th, 2006 11:06 PM
Unable to view XML content generated on-the-fly in IE 6.0 Rajiv Das answers 1 November 11th, 2005 11:10 PM
Error in IE torbs answers 9 October 22nd, 2005 06:25 PM
Getting event information in IE. Amir Hardon answers 6 July 20th, 2005 03:51 PM