Windows Scripting
  Home arrow Windows Scripting arrow Error Trapping and Capturing Third-Party O...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Error Trapping and Capturing Third-Party Output in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-03-05

    Table of Contents:
  • Error Trapping and Capturing Third-Party Output in WSH
  • Trapping Errors
  • Logging to the Event Log
  • Capturing Third-Party Output

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Error Trapping and Capturing Third-Party Output in WSH


    (Page 1 of 4 )

    In my last article we took an in-depth look at how to create log files for your scripts. In this article we are going to expand on that concept by teaching you how to trap events for a log file and how to capture third-party program output.

    Chances are that if you’re logging the actions of one of your scripts, what you really want to know is what, if anything went wrong.  After all, you’ve spent all that hard work making your life easier; it would be good to know it’s working as planned.

    The easiest way to do this is to know what actions produced errors.  The method of detecting errors with your script is known as error trapping.  Error handling is how your script reacts to that error.

    Understand that both error trapping and error handling are far beyond the scope of this article.  I just want to introduce the ideas to you because it’s often useful to trap errors when executing third-party programs as you’ll see later in this article.

    For our purposes we’re going to keep things simple.  WSH provides us with the Err object.  Any time an error occurs during execution, the error level is raised.  We can make frequent checks to the Err object to know when something hasn’t gone as planned.

    If we’re going to be handling our own errors, we don’t want our script to crash if one is encountered.  Therefore, we need to tell the script debugger to let our script run no matter what.  We do that by starting our script with the following line.

    On Error Resume Next

    This statement tells the script debugger to continue to the next operation whenever it encounters an operation that it can’t complete.  While this line is typically found at the beginning of a script file, you can use it within individual functions and subroutines.

    Properties

    object.Number [= number]

    object.Source [= string]

    object.Description [= string]

    object.HelpFile [= path]

    object.HelpContext [= context]

     

    Methods

    object.Raise number[, source, description, helpfile, helpcontext]

    object.Clear

    The Err object has several methods and properties.  The Number property is used to retrieve or set a runtime error number.  The Source property returns the source of an error in the form of a class name or programmatic ID.  The Description property is used to set or retrieve a text-based “friendly” description.  The HelpFile and HelpContext properties are used to set and retrieve the location of local help file and a context ID within that help file, respectively.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Hey, guys. In this article I'm wrapping up my logging concept by showing you how to...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT