"finally" not executing after a re-throw

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Peter X (peterx14_at_example.com)
Date: 11/15/04


Date: Mon, 15 Nov 2004 23:13:24 +0000

Hi all,

I've got a script that may throw an exception and that needs to release
a resource if that happens. However, I don't want to "handle" the
exception, since I can't... I don't know what it is yet! So I try, I
catch and re-throw, and I release resources in the finally block.
However, under WSH, the finally block isn't being executed. Example:

try {
   alert("try");
   nonExistantCall();
}
catch(e) {
   alert("catch e=[" + e + "]");
   throw e; // Re-throw.
}
finally {
   alert("finally");
}
alert("Complete!");

function alert(msg)
{
   var objShell = WScript.CreateObject("WScript.shell");
   objShell.Popup(msg);
}

If I save this as a .js file and click on it in Windows Explorer, I get
the "try", "catch" and the "WSH runtime error" (courtesy of the
re-throw). But no "finally" message!

The odd thing is, if I bung the same code into a web page (*without the
alert function*), then Internet Explorer will give me "try", "catch",
"finally" and *then* an Internet Explorer error.

So is JScript broken?

-- 
TIA!
Peter.


Relevant Pages

  • Re: need help with long processing app that will allow user to cancel process.
    ... > lengthly tasks. ... > we'll see a synchronization point protecting managment of heap blocks. ... you state one exception to this guide - class/instance factories. ... >> posting off the resource rather than waitFor'ing it. ...
    (borland.public.delphi.language.objectpascal)
  • OutOfMemoryException: major production problems
    ... On our production servers we receive the following events (in more detail ... * System.OutOfMemoryException: Exception of type System.OutOfMemoryException ... Failed to load resources from resource file ... The local computer may not have the necessary registry information or ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: whats the point in finally?
    ... throw new MyGenericException("Can parse xml", ... If you throw an exception from a destructor and the destructor is called due to an exception unwinding the stack then, IIRC, abort is called which by default calls terminate. ... Unfortunately "ownership" of the resource is moved into the decorator. ... In order to support such decorators, all resources can throw exceptions when being closed. ...
    (comp.lang.java.programmer)
  • Re: Evaluating Exceptions, Try Except and Try Finally
    ... work with the resource ... Consider your database example. ... exception handling differently than if the db open is something optional. ... both cases the code that actually opens the db shouldn't be the one making ...
    (alt.comp.lang.borland-delphi)
  • Re: Completism
    ... > My collection of convertiana has many, many very common items and ... As a resource, a complete collection is obviously more valuable than ... convinces them it is VALUABLE.] ... Another exception could be when ...
    (rec.collecting.books)