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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 3
    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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway