<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx</link><description>The way VBScript implements the error semantics I mentioned last time is sort of interesting. Today I'll talk a bit about the implementation details, and then next time I'll finish up by talking about some philosophy of error handling. Before I go on,</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#219182</link><pubDate>Tue, 24 Aug 2004 00:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:219182</guid><dc:creator>Norman Diamond</dc:creator><description>&amp;gt; Note that both On Error statements clear the&lt;br&gt;&amp;gt; recorded error information buffer.&lt;br&gt;&lt;br&gt;This seems to be a big difference between VBScript and VB.  I had developed the style of putting an On Error Goto handler_label before something whose failure I was prepared for, and two On Error Goto 0 statements, one just after the something and one at the beginning of the handler.&lt;br&gt;&lt;br&gt;But then for one VB application it made sense to have three of these in one function, and after handling and recovering from the first failure, the second failure aborted the function instead of getting sent to its handler.  I thought this was a VB bug but I was wrong.  Someone taught me that in VB the Resume statement must be executed IN ADDITION TO the On Error Goto 0 statement.  The Resume statement told the VB runtime to consider that the function had recovered from the failure (even though the function was still executing in the handler).  Then the second failure went to the second failure's handler.&lt;br&gt;&lt;br&gt;Suppose the program is being done in VBScript instead of VB, and suppose the developer can still anticipate some failures and wants to handle them and continue.  On Error Goto 0 is still a fine method of letting unexpected (unhandled) failures propagate upwards.  But if VBScript has no On Error Goto some_handler, and no need for a Resume statement, what is the usual method of handling an anticipated exception in VBScript?</description></item><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#219376</link><pubDate>Tue, 24 Aug 2004 12:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:219376</guid><dc:creator>Ron</dc:creator><description>Norman,&lt;br&gt;&lt;br&gt;The usual method [for VBScript] is by using On Error Resume Next and checking error codes after the statement executes.&lt;br&gt;&lt;br&gt;As for why the [VB] function didn't raise out of your error handler, once VB's handler is triggered, it's considered to be in handling mode until the function ends or a Resume statement is encountered.  If errors are expected in the error handler (and execution should not return back into the function body for the initial error), the handler should first issue a Resume to a label inside the error handler.  Then the On Error GoTo 0 will work as expected.</description></item><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#219914</link><pubDate>Wed, 25 Aug 2004 01:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:219914</guid><dc:creator>Norman Diamond</dc:creator><description>8/24/2004 5:34 AM Ron&lt;br&gt;&lt;br&gt;&amp;gt; The usual method [for VBScript] is by using&lt;br&gt;&amp;gt; On Error Resume Next and checking error&lt;br&gt;&amp;gt; codes after the statement executes.&lt;br&gt;&lt;br&gt;This must make some coding structures even more painful in VBScript than in VB.  Thank you for the information though.&lt;br&gt;&lt;br&gt;&amp;gt; As for why the [VB] function didn't raise&lt;br&gt;&amp;gt; out of your error handler&lt;br&gt;&lt;br&gt;Right, I said someone taught me that the Resume statement must be used IN ADDITION TO the On Error Goto 0 statement.&lt;br&gt;&lt;br&gt;By the way errors were not expected in the error handler (this is the reason I put an On Error Goto 0 at the beginning of the error handler).  But the handler Gotoed back to the normal chain of processing, and certain other possible errors were prepared for later (On Error Goto other_handler), but I didn't know at the time that the VB runtime still considered the function to be in handling mode and considered the new error a double fault.  So yes I put a Resume in the handler just after the handler's On Error Goto 0.  3 labels and visible gotos per handler.</description></item><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#221844</link><pubDate>Fri, 27 Aug 2004 23:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:221844</guid><dc:creator>foxyshadis</dc:creator><description>Curious about something. Does this mean that Resume Next is actually much slower than catching errors, because it terminates and restarts the interpreter every time? Or does this always happen, or did I just read that wrong?&lt;br&gt;&lt;br&gt;A side note: Goto sounds like a really messy brand of toy goop. It must be Friday. ^_^</description></item><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#221847</link><pubDate>Sat, 28 Aug 2004 00:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:221847</guid><dc:creator>Eric Lippert</dc:creator><description>First off, why the heck do you care how slow the error handler is?  Error conditions are almost never due to something fast, and are frequently followed up by showing an error message to the user.  Does it really matter whether it takes 30 ms or 40 ms to put up the &amp;quot;something failed&amp;quot; message box?&lt;br&gt;&lt;br&gt;Second, no, you're misunderstanding something. The interpreter is just a loop that fetches the next opcode and interprets it.  Resume Next saves away error information, moves the instruction pointer forwards to the next beginning-of-statement, and does a goto to the top of the interpreter loop.  Restarting the interpreter takes a couple billionths of a second.  Saving away the error strings for later is the expensive part.  (And that is under some circumstances deferrable, so you don't even incur that cost, but that is a topic for another day.)&lt;br&gt;&lt;br&gt;Not that it matters, but FWIW, catching errors a la jscript on the other hand is much slower.  Searching the call stack for exception handlers, then doing all the cleanup of the various stack frames, branching to the exception handler, and doing all the bookkeeping necessary to maintain integrity in situations where people do stupid things (like put an &amp;quot;eval('return;');&amp;quot; inside a finally --  ouch!) is much more complex and therefore slower than just resetting the instruction counter and continuing merrily along.&lt;br&gt;</description></item><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#224886</link><pubDate>Thu, 02 Sep 2004 19:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:224886</guid><dc:creator>Mark</dc:creator><description>How does IErrorInfo relate to EXCEPINFO? I have used IErrorInfo extensively in ATL COM objects to return error descriptions and source information back to VBScript, which seems to be what the EXCEPINFO structure does too? Are these two ways to do the same thing?</description></item><item><title>re: Error Handling In VBScript, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/08/23/218974.aspx#224928</link><pubDate>Thu, 02 Sep 2004 21:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:224928</guid><dc:creator>Eric Lippert</dc:creator><description>The point of IErrorInfo is to provide the information in an EXCEPINFO to objects that are designed to be called on vtable interfaces rather than via IDispatch.  &lt;br&gt;&lt;br&gt;VBScript doesn't use IErrorInfo because VBScirpt never calls via anything but IDispatch.  (OK, that's a lie; there is ONE special case which I will blog about at some point where we call IErrorInfo.)&lt;br&gt;&lt;br&gt;IErrorInfo is clearly the more &amp;quot;COM-like&amp;quot; way to do things.  Many problems -- like the ones I mention Spot The Defect Part Two -- could have been avoided had the OLE Automation designers chosen to pass back error information via an interface rather than a struct.&lt;br&gt;&lt;br&gt;Unfortunately the OLE Automation interfaces were written very early in the history of COM, back when it really wasn't so clear what exactly &amp;quot;COM-like&amp;quot; meant.  From a design perspective, lots of OLE Automation is essentially just a thin COM wrapper overtop of a Win32-API-style-hey-let's-pass-some-pointers-to-structs-around model.  EXCEPINFO is part of that.  Were we to design late-bound dispatch interfaces in COM today, they'd use interfaces like IErrorInfo.  But, sadly, we're stuck with two ways to do the same thing.</description></item></channel></rss>