SlideShare a Scribd company logo
1
VBScript
Session 12
2
What We’ve learned last session?
 What is OOP and the OOP model.
 What is an object, how to create an object, use
methods, properties and attribures
 How to set object to variables, and how to free the
variables.
 What is a collection and a container object.
 What is COM objects, how do they defined
 The FileSystem object, how to create,delete,read,copy
files and directories, how to get system information.
Last session was for begginers
3
Subjects for session 12
 Error Handling
 On Error statements
 On Error Goto 0
 On Error Resume Next
 Err Object
 Methods.
 Properties.
 vbObjectError constant
4
Error Handling
Expect the Unexpected!
There are two ways of producing error-free software.
But only the third will work ...
Unknown Author
What we anticipate seldom occurs; what we least
expected generally happens.
Benjamin Disraeli
5
Error Handling
Why?
 There are bugs than can eliminate an entire project.
 There are also bugs that can kill people.
 Reliability is a major characteristic of high-quality
software.
 Software should behave well in nearly every situation.
 During the development process we try to avoid, detect
and remove as many errors as possible.
 We cannot assume that the delivered software is free
of errors. Therefore, we have to think about
mechanisms to protect the productive system from
unacceptable behaviour while erroneous situations
occurs.
6
Error Handling
Goals
 We want to be prepared for the program changing
into a bad state.
 In most cases there will be no return from the bad
state to a good state and the program has to be
terminated in a controlled way.
 Of course, whenever possible the program tries to
get out of trouble by itself, but normally it would be
very difficult to recover from a serious error
situation.
 During specification the boundary between the
normal, abnormal and erroneous behaviour is drawn
and this boundary remains visible down to the code.
7
Error Handling
Goals
 We want to minimize the set of disastrous
states by foreseeing these situations and
thus converting them to expected
situations.
 An error handling concept defines which
errors must be distinguished and how the
system reacts to these errors.
 Such a concept can be very simple or very
complicated.
8
Error Handling
Terminology
Fault Error Failure
Detector Exception
Causes Causes
RaisesDetects
Detects
9
Error Handling
Terminology - Fault
 A fault is the origin of any
misbehaviour.
 One can distinguish between design
faults (software bugs), hardware
faults, lower level service faults,
and specification faults.
10
Error Handling
Terminology - Error
 A user error is a mistake made by a user when
operating a software system.
 The system is able to react to these mistakes,
because it is designed to expect such situations
and it is a part of the required functionality.
 The handling of those situations, which of course
can be abnormal, should be treated in the user
interface component of the system.
 In contrast to an error, a user error (hopefully)
can not result in a system crash, but like a
system error, a user error normally can result in
an exception raised by a system component.
11
Error Handling
Terminology - Failure
 A failure is a deviation of the
delivered service from compliance
with the specification.
 Whereas an error characterizes a
particular state of a system, a
failure is a particular event namely
the transition from correct service
delivery to incorrect service.
12
Error Handling
Terminology - Detector
 Before software can react to any error it has to
detect one first.
 If we look at the error handling as a separate
software system, errors and failures of an
application are the phenomena the error handling
system observes.
 Thus a detector is the interface between the error
and failures happening outside and their internal
handling.
 The number, place and kind of detectors have
great impact on the quality of an error handling
system.
13
Error Handling
Terminology - Exception
 Generally, any occurrence of an abnormal condition that
causes an interruption in normal control flow is called an
exception.
 It is said that an exception is raised (thrown) when such a
condition is signaled by a software unit.
 In response to an exception, the control is immediately given
to a designated handler for the exception, which reacts to
that situation (exception handler).
 The handler can try to recover from that exception in order to
continue at a prede-fined location or it cleans up the
environment and further escalates the exception.
 exceptions are not only a mechanism which can be used to
handle errors and program failures.
14
Error Handling
Summary
 No software system can be assumed to behave totally
correct.
 Even careful testing and the use of formal methods
does not guarantee error-free software, hence we
cannot rely on a “perfect world” assumption.
 Because we cannot prevent errors we have to live with
them.
 The software must be able to detect errors and to
defeat them with appropriate recovery techniques and
mechanisms in order to restore normal operation.
15
On Error Statements
 Enables or disables error-handling.
 If you don't use an On Error Resume Next
statement anywhere in your code, any run-time
error that occurs can cause an error message to
be displayed and code execution stopped.
 This sample of error message generated when
trying to open a file that not exists.
16
On Error Statements
 However, the host running the code determines
the exact behavior.
 The host can sometimes opt to handle such errors
differently.
 In some cases, the script debugger may be
invoked at the point of the error.
 n still other cases, there may be no apparent
indication that any error occurred because the
host does not to notify the user.
 Again, this is purely a function of how the host
handles any errors that occur.
17
On Error Statements
 Within any particular procedure, an error is not
necessarily fatal as long as error-handling is
enabled somewhere along the call stack.
 If local error-handling is not enabled in a
procedure and an error occurs, control is passed
back through the call stack until a procedure with
error-handling enabled is found and the error is
handled at that point.
 If no procedure in the call stack is found to have
error-handling enabled, an error message is
displayed at that point and execution stops or the
host handles the error as appropriate.
18
On Error Resume Next
 uses execution to continue with the statement immediately
following the statement that caused the run-time error, or
with the statement immediately following the most recent call
out of the procedure containing the On Error Resume Next
statement.
 his allows execution to continue despite a run-time error.
 You can then build the error-handling routine inline within the
procedure.
 An On Error Resume Next statement becomes inactive
when another procedure is called, so you should execute an
On Error Resume Next statement in each called routine if
you want inline error handling within that routine.
19
On Error Resume Next
 hen a procedure is exited, the error-
handling capability reverts to whatever
error-handling was in place before
entering the exited procedure.
 Use On Error GoTo 0 to disable error
handling if you have previously enabled it
using On Error Resume Next.
20
On Error Resume Next
 hen a procedure is exited, the error-
handling capability reverts to whatever
error-handling was in place before
entering the exited procedure.
 Use On Error GoTo 0 to disable error
handling if you have previously enabled it
using On Error Resume Next.
21
On Error Resume Next
Pros and Cons
 Episode of the Simpsons (Notes)
 Problem: On Error Resume Next doesn’t actually fix the
problem, it merely removes it from view.
 On Error Resume Next is no miracle cure for scripting.
 When you start a script, assuming there are no syntax
errors that would cause the script to crash before it
ever gets going, WSH tries to run the first line of code.
 If the line runs successfully, WSH then tries to run the
second line of code.
 This process continues until each line of code has been
executed.
 At that point, the script automatically terminates.
22
On Error Resume Next
Pros and Cons
 But what if WSH encounters a line of code that it can’t
run successfully? Without On Error Resume Next, the
script would come to a crashing halt, the script process
would end, and an error message would be displayed.
 If you’ve included On Error Resume Next, however, the
script typically won’t blow up; instead, WSH will simply
skip the line it can’t run and try running the next line.
 100-line script sample.
 There’s definitely value in having a script that can
recover from errors, especially when that script is being
used by other people.
23
On Error Resume Next
Why? When? How?
 We have here a simple code :
 Notice the mistake we made in line 3: instead of
typing b = 2, we typed b 2:
On Error Resume Next
Dim a
a = 1
b 2
MsgBox a+b
 The answer you will get is 1
 we’ve managed to turn our fancy new computer
into a machine that can’t even add 2 and 1!
24
On Error Resume Next
Why? When? How?
 B 2 is not a valid statement, and when WSH
encounters this line an error occurs.
 However, On Error Resume Next suppresses this
error.
 WSH then attempts to run the next line of code,
something which, in this case, leads to problems.
 Because of that, B is not assigned the value 2.
 And because no value has been assigned to B, it
automatically assumes the value of 0.
25
On Error Resume Next
Why? When? How?
 Because you know that this answer is wrong (I
hope) and because this script is so short, you
probably know that the script needs debugging
 In this case, then, debugging the script is easy.
 But suppose this script was several hundred lines
long, and suppose this was a much more
complicated mathematical equation.
 In that case, you might not know that the answer
was wrong; even if you did, you might have
trouble tracking down the problem.
26
On Error Resume Next
Why? When? How?
 Running now tge script again will cause the follow
message to be displayed
 This time there’s no question about whether the script
worked or not, and we don’t have to puzzle over whether
2 + 1 actually does equal 1. We know for sure that we
have problems.
27
On Error Resume Next
Why? When? How?
 Often in larger scripts we move to step 2
 There are two things we need to do here.
 First, read the error message.
 Second, pay attention to the line number reported
in the error message.
 Step 3 figure out the problem based on the error
message, one thing you can do is look up the
error code (800A000D) at the Microsoft Support
site or VBScript documenatation, don’t forget that
the value is hexadecimal so convert only the last
4 digits (000D) to a decimal number (13)
 For this Error in the VBScript documentation you
will get “Type Mismatch”
28
On Error Resume Next
Why? When? How?
 For larger scripts is recommended
to implement the following routines
 Break your script into sections and test
each section separately. Make sure
each individual section is working
before you re-test the script as a
whole.
 Implement a Trace Routine using
msgboxes, acommand-line tool or
displaying messages to the screen.
29
On Error Resume Next
Why? When? How?
 Step 1: Get Rid of On Error Resume Next
 whenever you are working on a script and
whenever you suspect something has
gone wrong, your first step should always
be to remove or remark On Error Resume
Next.
 A better moral might be this: On Error
Resume Next should typically be the last
thing you add to a script, not the first
thing.
30
Err Object
 Contains information about run-time errors.
 The Err object is an intrinsic object with global
scope — there is no need to create an instance of
it in your code.
 The properties of the Err object are set by the
generator of an error — Visual Basic, an
Automation object, or the VBScript programmer.
 The default property of the Err object is Number.
 Err.Number contains an integer and can be used
by an Automation object to return an SCODE.
31
Err Object
 When a run-time error occurs, the properties of
the Err object are filled with information that
uniquely identifies the error and information that
can be used to handle it.
 To generate a run-time error in your code, use
the Raise method.
 The Err object's properties are reset to zero or
zero-length strings ("") after an On Error
Resume Next statement.
 The Clear method can be used to explicitly reset
Err.
32
Err Object Properties and Methods
Number Property
 object.Number [= errornumber]
 Returns or sets a numeric value specifying an
error.
 Number is the Err object's default property.
 When returning a user-defined error from an
Automation object, set Err.Number by adding
the number you selected as an error code to the
constant vbObjectError.
33
Err Object Properties and Methods
Description Property
 object.Description [= stringexpression]
 Returns or sets a descriptive string associated with an error.
 The Description property consists of a short description of
the error.
 Use this property to alert the user to an error that you can't
or don't want to handle.
 When generating a user-defined error, assign a short
description of your error to this property.
 If Description isn't filled in, and the value of Number
corresponds to a VBScript run-time error, the descriptive
string associated with the error is returned.
34
Err Object Properties and Methods
Source Property
 object.Source [= stringexpression]
 Returns or sets the name of the object or application that
originally generated the error.
 The Source property specifies a string expression that is
usually the class name or programmatic ID of the object that
caused the error.
 Use Source to provide your users with information when
your code is unable to handle an error generated in an
accessed object.
 For example, if you access Microsoft Excel and it generates a
Division by zero error, Microsoft Excel sets Err.Number to its
error code for that error and sets Source to
Excel.Application.
35
Err Object Properties and Methods
Source Property
 Source always contains the name of the object
that originally generated the error.
 your code can try to handle the error according to
the error documentation of the object you
accessed.
 If your error handler fails, you can use the Err
object information to describe the error to your
user, using Source and the other Err to inform
the user which object originally caused the error,
its description of the error, and so forth.
36
Err Object Properties and Methods
Help File Property
 object.HelpFile [= contextID]
 Sets or returns a fully qualified path to a Help File.
 The contextID is a fully qualified path to the Help file.
 If a Help file is specified in HelpFile, it is automatically
called when the user clicks the Help button (or presses
the F1 key) in the error message dialog box.
 If the HelpContext property contains a valid context
ID for the specified file, that topic is automatically
displayed.
 If no HelpFile is specified, the VBScript Help file is
displayed.
37
Err Object Properties and Methods
Help Context Property
 object.HelpContext [= contextID]
 Sets or returns a context ID for a topic in a Help File.
 The contextID is a valid identifier for a Help topic within the Help
file.
 If a Help file is specified in HelpFile, the HelpContext property
is used to automatically display the Help topic identified.
 If both HelpFile and HelpContext are empty, the value of the
Number property is checked.
 If it corresponds to a VBScript run-time error value, then the
VBScript Help context ID for the error is used.
 If the Number property doesn't correspond to a VBScript error,
the contents screen for the VBScript Help file is displayed.
38
Err Object Properties and Methods
Clear Method
 object.Clear
 Clears all property settings of the Err object.
 Use Clear to explicitly clear the Err object after an
error has been handled.
 This is necessary, for example, when you use deferred
error handling with On Error Resume Next.
 VBScript calls the Clear method automatically
whenever any of the following statements is executed:
 On Error Resume Next
 Exit Sub
 Exit Function
39
Err Object Properties and Methods
Raise Method
 object.Raise(number, source, description, helpfile, helpcontext)
 Generates a run-time error.
 All the arguments are optional except number.
 If you use Raise, however, without specifying some
arguments, and the property settings of the Err object
contain values that have not been cleared, those values
become the values for your error.
 When setting the number property to your own error code in
an Automation object, you add your error code number to the
constant vbObjectError.
 For example, to generate the error number 1050, assign
vbObjectError + 1050 to the number property.
40
What’s Next?
 Regulars Expressions.
 Methods and properties.
 How to use the object and the
object collections.
 How to create complex patterns.

More Related Content

What's hot

Java Exceptions
Java ExceptionsJava Exceptions
Java Exceptions
jalinder123
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
Lemi Orhan Ergin
 
Error handling
Error handlingError handling
Error handling
Meherul1234
 
Debugging
DebuggingDebugging
Debugging
nicky_walters
 
Chapter13 exception handling
Chapter13 exception handlingChapter13 exception handling
Chapter13 exception handling
Prabhakar Nallabolu
 
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStringsProgramming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
Alan Richardson
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
 
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
Alan Richardson
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to help
PVS-Studio
 
The compiler is to blame for everything
The compiler is to blame for everythingThe compiler is to blame for everything
The compiler is to blame for everything
PVS-Studio
 
Exception Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRException Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLR
Kiran Munir
 
Presentation1
Presentation1Presentation1
Presentation1
Anul Chaudhary
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
Narayana Swamy
 
Understanding Exception Handling in .Net
Understanding Exception Handling in .NetUnderstanding Exception Handling in .Net
Understanding Exception Handling in .Net
Mindfire Solutions
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
Shipra Swati
 
De so 1
De so 1De so 1
De so 1
kiennt
 
Exception handling
Exception handlingException handling
Exception handling
Garuda Trainings
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
ankitgarg_er
 
Exception handling
Exception handlingException handling
Exception handling
Abhishek Pachisia
 

What's hot (19)

Java Exceptions
Java ExceptionsJava Exceptions
Java Exceptions
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
 
Error handling
Error handlingError handling
Error handling
 
Debugging
DebuggingDebugging
Debugging
 
Chapter13 exception handling
Chapter13 exception handlingChapter13 exception handling
Chapter13 exception handling
 
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStringsProgramming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
 
The D language comes to help
The D language comes to helpThe D language comes to help
The D language comes to help
 
The compiler is to blame for everything
The compiler is to blame for everythingThe compiler is to blame for everything
The compiler is to blame for everything
 
Exception Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRException Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLR
 
Presentation1
Presentation1Presentation1
Presentation1
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
 
Understanding Exception Handling in .Net
Understanding Exception Handling in .NetUnderstanding Exception Handling in .Net
Understanding Exception Handling in .Net
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
De so 1
De so 1De so 1
De so 1
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Exception handling
Exception handlingException handling
Exception handling
 

Viewers also liked

Vbscript
VbscriptVbscript
Tema 8 y 10
Tema 8 y 10Tema 8 y 10
Tema 8 y 10
UFT
 
Tanatologia jhonathan
Tanatologia   jhonathanTanatologia   jhonathan
Tanatologia jhonathan
UFT
 
Anchors!
Anchors!Anchors!
Anchors!
mrivas1114
 
Learn VbScript -String Functions
Learn VbScript -String FunctionsLearn VbScript -String Functions
Learn VbScript -String Functions
Nilanjan Saha
 
VBScript Tutorial
VBScript TutorialVBScript Tutorial
VBScript Tutorial
Leminy
 
Introduction to Oracle RMAN, backup and recovery tool.
Introduction to Oracle RMAN, backup and recovery tool.Introduction to Oracle RMAN, backup and recovery tool.
Introduction to Oracle RMAN, backup and recovery tool.
guest5ac6fb
 
vb script
vb scriptvb script
vb script
Anand Dhana
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScript
Vitaliy Ganzha
 
Html creating page link or hyperlink
Html creating page link or hyperlinkHtml creating page link or hyperlink
Html creating page link or hyperlink
argusacademy
 
Anchor tag HTML Presentation
Anchor tag HTML PresentationAnchor tag HTML Presentation
Anchor tag HTML Presentation
Nimish Gupta
 
Introduction to Unified Functional Testing 12 (UFT)
Introduction to Unified Functional Testing 12 (UFT)Introduction to Unified Functional Testing 12 (UFT)
Introduction to Unified Functional Testing 12 (UFT)
Archana Krushnan
 
VB Script
VB ScriptVB Script
VB Script
Satish Sukumaran
 
QTP VB Script Trainings
QTP VB Script TrainingsQTP VB Script Trainings
QTP VB Script Trainings
Ali Imran
 
Cse new graduate_students2011
Cse new graduate_students2011Cse new graduate_students2011
Cse new graduate_students2011
Masoud Nikravesh
 
Ramanathan A - CV
Ramanathan A - CVRamanathan A - CV
Ramanathan A - CV
Athilingam Ramanathan
 
Who is the target audience for my thriller
Who is the target audience for my thrillerWho is the target audience for my thriller
Who is the target audience for my thriller
tubze_t
 
Kt product catalogue s s
Kt product catalogue s sKt product catalogue s s
Kt product catalogue s s
Sohail Ahmed
 
CV
CVCV
VENKATRAMANI RESUME
VENKATRAMANI RESUMEVENKATRAMANI RESUME
VENKATRAMANI RESUME
venkat ramani
 

Viewers also liked (20)

Vbscript
VbscriptVbscript
Vbscript
 
Tema 8 y 10
Tema 8 y 10Tema 8 y 10
Tema 8 y 10
 
Tanatologia jhonathan
Tanatologia   jhonathanTanatologia   jhonathan
Tanatologia jhonathan
 
Anchors!
Anchors!Anchors!
Anchors!
 
Learn VbScript -String Functions
Learn VbScript -String FunctionsLearn VbScript -String Functions
Learn VbScript -String Functions
 
VBScript Tutorial
VBScript TutorialVBScript Tutorial
VBScript Tutorial
 
Introduction to Oracle RMAN, backup and recovery tool.
Introduction to Oracle RMAN, backup and recovery tool.Introduction to Oracle RMAN, backup and recovery tool.
Introduction to Oracle RMAN, backup and recovery tool.
 
vb script
vb scriptvb script
vb script
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScript
 
Html creating page link or hyperlink
Html creating page link or hyperlinkHtml creating page link or hyperlink
Html creating page link or hyperlink
 
Anchor tag HTML Presentation
Anchor tag HTML PresentationAnchor tag HTML Presentation
Anchor tag HTML Presentation
 
Introduction to Unified Functional Testing 12 (UFT)
Introduction to Unified Functional Testing 12 (UFT)Introduction to Unified Functional Testing 12 (UFT)
Introduction to Unified Functional Testing 12 (UFT)
 
VB Script
VB ScriptVB Script
VB Script
 
QTP VB Script Trainings
QTP VB Script TrainingsQTP VB Script Trainings
QTP VB Script Trainings
 
Cse new graduate_students2011
Cse new graduate_students2011Cse new graduate_students2011
Cse new graduate_students2011
 
Ramanathan A - CV
Ramanathan A - CVRamanathan A - CV
Ramanathan A - CV
 
Who is the target audience for my thriller
Who is the target audience for my thrillerWho is the target audience for my thriller
Who is the target audience for my thriller
 
Kt product catalogue s s
Kt product catalogue s sKt product catalogue s s
Kt product catalogue s s
 
CV
CVCV
CV
 
VENKATRAMANI RESUME
VENKATRAMANI RESUMEVENKATRAMANI RESUME
VENKATRAMANI RESUME
 

Similar to VBscript

Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
talha ijaz
 
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
NALANDACSCCENTRE
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
amiralicomsats3
 
Maheen oop
Maheen oopMaheen oop
Maheen oop
mahshah212
 
Debugging
DebuggingDebugging
Debugging
Ajeng Savitri
 
Error Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctypError Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctyp
BhuvaneswariR27
 
Error Handling in Compiler Design.What a
Error Handling in Compiler Design.What aError Handling in Compiler Design.What a
Error Handling in Compiler Design.What a
BhuvaneswariR27
 
Error Handling in Compiler Design.typeso
Error Handling in Compiler Design.typesoError Handling in Compiler Design.typeso
Error Handling in Compiler Design.typeso
BhuvaneswariR27
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
suraj pandey
 
Lecture 22 - Error Handling
Lecture 22 - Error HandlingLecture 22 - Error Handling
Lecture 22 - Error Handling
Md. Imran Hossain Showrov
 
Exception handling
Exception handlingException handling
Exception handling
Raja Sekhar
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Ankit Rai
 
Exception handling
Exception handlingException handling
Exception handling
Karthik Sekar
 
100% code coverage by static analysis - is it that good?
100% code coverage by static analysis - is it that good?100% code coverage by static analysis - is it that good?
100% code coverage by static analysis - is it that good?
PVS-Studio
 
The Pragmatic Programmer
The Pragmatic ProgrammerThe Pragmatic Programmer
The Pragmatic Programmer
Sena Uzun
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
Rathna Priya
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
Rathna Priya
 
Chapter 2 program-security
Chapter 2 program-securityChapter 2 program-security
Chapter 2 program-security
Vamsee Krishna Kiran
 
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfDifferent Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
pCloudy
 
Mule soft meetup__dubai_12_june- Error Handling
Mule soft meetup__dubai_12_june- Error HandlingMule soft meetup__dubai_12_june- Error Handling
Mule soft meetup__dubai_12_june- Error Handling
satyasekhar123
 

Similar to VBscript (20)

Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
 
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
 
Maheen oop
Maheen oopMaheen oop
Maheen oop
 
Debugging
DebuggingDebugging
Debugging
 
Error Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctypError Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctyp
 
Error Handling in Compiler Design.What a
Error Handling in Compiler Design.What aError Handling in Compiler Design.What a
Error Handling in Compiler Design.What a
 
Error Handling in Compiler Design.typeso
Error Handling in Compiler Design.typesoError Handling in Compiler Design.typeso
Error Handling in Compiler Design.typeso
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
Lecture 22 - Error Handling
Lecture 22 - Error HandlingLecture 22 - Error Handling
Lecture 22 - Error Handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Exception handling
Exception handlingException handling
Exception handling
 
100% code coverage by static analysis - is it that good?
100% code coverage by static analysis - is it that good?100% code coverage by static analysis - is it that good?
100% code coverage by static analysis - is it that good?
 
The Pragmatic Programmer
The Pragmatic ProgrammerThe Pragmatic Programmer
The Pragmatic Programmer
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
 
Chapter 2 program-security
Chapter 2 program-securityChapter 2 program-security
Chapter 2 program-security
 
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfDifferent Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
 
Mule soft meetup__dubai_12_june- Error Handling
Mule soft meetup__dubai_12_june- Error HandlingMule soft meetup__dubai_12_june- Error Handling
Mule soft meetup__dubai_12_june- Error Handling
 

Recently uploaded

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 

Recently uploaded (20)

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 

VBscript

  • 2. 2 What We’ve learned last session?  What is OOP and the OOP model.  What is an object, how to create an object, use methods, properties and attribures  How to set object to variables, and how to free the variables.  What is a collection and a container object.  What is COM objects, how do they defined  The FileSystem object, how to create,delete,read,copy files and directories, how to get system information. Last session was for begginers
  • 3. 3 Subjects for session 12  Error Handling  On Error statements  On Error Goto 0  On Error Resume Next  Err Object  Methods.  Properties.  vbObjectError constant
  • 4. 4 Error Handling Expect the Unexpected! There are two ways of producing error-free software. But only the third will work ... Unknown Author What we anticipate seldom occurs; what we least expected generally happens. Benjamin Disraeli
  • 5. 5 Error Handling Why?  There are bugs than can eliminate an entire project.  There are also bugs that can kill people.  Reliability is a major characteristic of high-quality software.  Software should behave well in nearly every situation.  During the development process we try to avoid, detect and remove as many errors as possible.  We cannot assume that the delivered software is free of errors. Therefore, we have to think about mechanisms to protect the productive system from unacceptable behaviour while erroneous situations occurs.
  • 6. 6 Error Handling Goals  We want to be prepared for the program changing into a bad state.  In most cases there will be no return from the bad state to a good state and the program has to be terminated in a controlled way.  Of course, whenever possible the program tries to get out of trouble by itself, but normally it would be very difficult to recover from a serious error situation.  During specification the boundary between the normal, abnormal and erroneous behaviour is drawn and this boundary remains visible down to the code.
  • 7. 7 Error Handling Goals  We want to minimize the set of disastrous states by foreseeing these situations and thus converting them to expected situations.  An error handling concept defines which errors must be distinguished and how the system reacts to these errors.  Such a concept can be very simple or very complicated.
  • 8. 8 Error Handling Terminology Fault Error Failure Detector Exception Causes Causes RaisesDetects Detects
  • 9. 9 Error Handling Terminology - Fault  A fault is the origin of any misbehaviour.  One can distinguish between design faults (software bugs), hardware faults, lower level service faults, and specification faults.
  • 10. 10 Error Handling Terminology - Error  A user error is a mistake made by a user when operating a software system.  The system is able to react to these mistakes, because it is designed to expect such situations and it is a part of the required functionality.  The handling of those situations, which of course can be abnormal, should be treated in the user interface component of the system.  In contrast to an error, a user error (hopefully) can not result in a system crash, but like a system error, a user error normally can result in an exception raised by a system component.
  • 11. 11 Error Handling Terminology - Failure  A failure is a deviation of the delivered service from compliance with the specification.  Whereas an error characterizes a particular state of a system, a failure is a particular event namely the transition from correct service delivery to incorrect service.
  • 12. 12 Error Handling Terminology - Detector  Before software can react to any error it has to detect one first.  If we look at the error handling as a separate software system, errors and failures of an application are the phenomena the error handling system observes.  Thus a detector is the interface between the error and failures happening outside and their internal handling.  The number, place and kind of detectors have great impact on the quality of an error handling system.
  • 13. 13 Error Handling Terminology - Exception  Generally, any occurrence of an abnormal condition that causes an interruption in normal control flow is called an exception.  It is said that an exception is raised (thrown) when such a condition is signaled by a software unit.  In response to an exception, the control is immediately given to a designated handler for the exception, which reacts to that situation (exception handler).  The handler can try to recover from that exception in order to continue at a prede-fined location or it cleans up the environment and further escalates the exception.  exceptions are not only a mechanism which can be used to handle errors and program failures.
  • 14. 14 Error Handling Summary  No software system can be assumed to behave totally correct.  Even careful testing and the use of formal methods does not guarantee error-free software, hence we cannot rely on a “perfect world” assumption.  Because we cannot prevent errors we have to live with them.  The software must be able to detect errors and to defeat them with appropriate recovery techniques and mechanisms in order to restore normal operation.
  • 15. 15 On Error Statements  Enables or disables error-handling.  If you don't use an On Error Resume Next statement anywhere in your code, any run-time error that occurs can cause an error message to be displayed and code execution stopped.  This sample of error message generated when trying to open a file that not exists.
  • 16. 16 On Error Statements  However, the host running the code determines the exact behavior.  The host can sometimes opt to handle such errors differently.  In some cases, the script debugger may be invoked at the point of the error.  n still other cases, there may be no apparent indication that any error occurred because the host does not to notify the user.  Again, this is purely a function of how the host handles any errors that occur.
  • 17. 17 On Error Statements  Within any particular procedure, an error is not necessarily fatal as long as error-handling is enabled somewhere along the call stack.  If local error-handling is not enabled in a procedure and an error occurs, control is passed back through the call stack until a procedure with error-handling enabled is found and the error is handled at that point.  If no procedure in the call stack is found to have error-handling enabled, an error message is displayed at that point and execution stops or the host handles the error as appropriate.
  • 18. 18 On Error Resume Next  uses execution to continue with the statement immediately following the statement that caused the run-time error, or with the statement immediately following the most recent call out of the procedure containing the On Error Resume Next statement.  his allows execution to continue despite a run-time error.  You can then build the error-handling routine inline within the procedure.  An On Error Resume Next statement becomes inactive when another procedure is called, so you should execute an On Error Resume Next statement in each called routine if you want inline error handling within that routine.
  • 19. 19 On Error Resume Next  hen a procedure is exited, the error- handling capability reverts to whatever error-handling was in place before entering the exited procedure.  Use On Error GoTo 0 to disable error handling if you have previously enabled it using On Error Resume Next.
  • 20. 20 On Error Resume Next  hen a procedure is exited, the error- handling capability reverts to whatever error-handling was in place before entering the exited procedure.  Use On Error GoTo 0 to disable error handling if you have previously enabled it using On Error Resume Next.
  • 21. 21 On Error Resume Next Pros and Cons  Episode of the Simpsons (Notes)  Problem: On Error Resume Next doesn’t actually fix the problem, it merely removes it from view.  On Error Resume Next is no miracle cure for scripting.  When you start a script, assuming there are no syntax errors that would cause the script to crash before it ever gets going, WSH tries to run the first line of code.  If the line runs successfully, WSH then tries to run the second line of code.  This process continues until each line of code has been executed.  At that point, the script automatically terminates.
  • 22. 22 On Error Resume Next Pros and Cons  But what if WSH encounters a line of code that it can’t run successfully? Without On Error Resume Next, the script would come to a crashing halt, the script process would end, and an error message would be displayed.  If you’ve included On Error Resume Next, however, the script typically won’t blow up; instead, WSH will simply skip the line it can’t run and try running the next line.  100-line script sample.  There’s definitely value in having a script that can recover from errors, especially when that script is being used by other people.
  • 23. 23 On Error Resume Next Why? When? How?  We have here a simple code :  Notice the mistake we made in line 3: instead of typing b = 2, we typed b 2: On Error Resume Next Dim a a = 1 b 2 MsgBox a+b  The answer you will get is 1  we’ve managed to turn our fancy new computer into a machine that can’t even add 2 and 1!
  • 24. 24 On Error Resume Next Why? When? How?  B 2 is not a valid statement, and when WSH encounters this line an error occurs.  However, On Error Resume Next suppresses this error.  WSH then attempts to run the next line of code, something which, in this case, leads to problems.  Because of that, B is not assigned the value 2.  And because no value has been assigned to B, it automatically assumes the value of 0.
  • 25. 25 On Error Resume Next Why? When? How?  Because you know that this answer is wrong (I hope) and because this script is so short, you probably know that the script needs debugging  In this case, then, debugging the script is easy.  But suppose this script was several hundred lines long, and suppose this was a much more complicated mathematical equation.  In that case, you might not know that the answer was wrong; even if you did, you might have trouble tracking down the problem.
  • 26. 26 On Error Resume Next Why? When? How?  Running now tge script again will cause the follow message to be displayed  This time there’s no question about whether the script worked or not, and we don’t have to puzzle over whether 2 + 1 actually does equal 1. We know for sure that we have problems.
  • 27. 27 On Error Resume Next Why? When? How?  Often in larger scripts we move to step 2  There are two things we need to do here.  First, read the error message.  Second, pay attention to the line number reported in the error message.  Step 3 figure out the problem based on the error message, one thing you can do is look up the error code (800A000D) at the Microsoft Support site or VBScript documenatation, don’t forget that the value is hexadecimal so convert only the last 4 digits (000D) to a decimal number (13)  For this Error in the VBScript documentation you will get “Type Mismatch”
  • 28. 28 On Error Resume Next Why? When? How?  For larger scripts is recommended to implement the following routines  Break your script into sections and test each section separately. Make sure each individual section is working before you re-test the script as a whole.  Implement a Trace Routine using msgboxes, acommand-line tool or displaying messages to the screen.
  • 29. 29 On Error Resume Next Why? When? How?  Step 1: Get Rid of On Error Resume Next  whenever you are working on a script and whenever you suspect something has gone wrong, your first step should always be to remove or remark On Error Resume Next.  A better moral might be this: On Error Resume Next should typically be the last thing you add to a script, not the first thing.
  • 30. 30 Err Object  Contains information about run-time errors.  The Err object is an intrinsic object with global scope — there is no need to create an instance of it in your code.  The properties of the Err object are set by the generator of an error — Visual Basic, an Automation object, or the VBScript programmer.  The default property of the Err object is Number.  Err.Number contains an integer and can be used by an Automation object to return an SCODE.
  • 31. 31 Err Object  When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle it.  To generate a run-time error in your code, use the Raise method.  The Err object's properties are reset to zero or zero-length strings ("") after an On Error Resume Next statement.  The Clear method can be used to explicitly reset Err.
  • 32. 32 Err Object Properties and Methods Number Property  object.Number [= errornumber]  Returns or sets a numeric value specifying an error.  Number is the Err object's default property.  When returning a user-defined error from an Automation object, set Err.Number by adding the number you selected as an error code to the constant vbObjectError.
  • 33. 33 Err Object Properties and Methods Description Property  object.Description [= stringexpression]  Returns or sets a descriptive string associated with an error.  The Description property consists of a short description of the error.  Use this property to alert the user to an error that you can't or don't want to handle.  When generating a user-defined error, assign a short description of your error to this property.  If Description isn't filled in, and the value of Number corresponds to a VBScript run-time error, the descriptive string associated with the error is returned.
  • 34. 34 Err Object Properties and Methods Source Property  object.Source [= stringexpression]  Returns or sets the name of the object or application that originally generated the error.  The Source property specifies a string expression that is usually the class name or programmatic ID of the object that caused the error.  Use Source to provide your users with information when your code is unable to handle an error generated in an accessed object.  For example, if you access Microsoft Excel and it generates a Division by zero error, Microsoft Excel sets Err.Number to its error code for that error and sets Source to Excel.Application.
  • 35. 35 Err Object Properties and Methods Source Property  Source always contains the name of the object that originally generated the error.  your code can try to handle the error according to the error documentation of the object you accessed.  If your error handler fails, you can use the Err object information to describe the error to your user, using Source and the other Err to inform the user which object originally caused the error, its description of the error, and so forth.
  • 36. 36 Err Object Properties and Methods Help File Property  object.HelpFile [= contextID]  Sets or returns a fully qualified path to a Help File.  The contextID is a fully qualified path to the Help file.  If a Help file is specified in HelpFile, it is automatically called when the user clicks the Help button (or presses the F1 key) in the error message dialog box.  If the HelpContext property contains a valid context ID for the specified file, that topic is automatically displayed.  If no HelpFile is specified, the VBScript Help file is displayed.
  • 37. 37 Err Object Properties and Methods Help Context Property  object.HelpContext [= contextID]  Sets or returns a context ID for a topic in a Help File.  The contextID is a valid identifier for a Help topic within the Help file.  If a Help file is specified in HelpFile, the HelpContext property is used to automatically display the Help topic identified.  If both HelpFile and HelpContext are empty, the value of the Number property is checked.  If it corresponds to a VBScript run-time error value, then the VBScript Help context ID for the error is used.  If the Number property doesn't correspond to a VBScript error, the contents screen for the VBScript Help file is displayed.
  • 38. 38 Err Object Properties and Methods Clear Method  object.Clear  Clears all property settings of the Err object.  Use Clear to explicitly clear the Err object after an error has been handled.  This is necessary, for example, when you use deferred error handling with On Error Resume Next.  VBScript calls the Clear method automatically whenever any of the following statements is executed:  On Error Resume Next  Exit Sub  Exit Function
  • 39. 39 Err Object Properties and Methods Raise Method  object.Raise(number, source, description, helpfile, helpcontext)  Generates a run-time error.  All the arguments are optional except number.  If you use Raise, however, without specifying some arguments, and the property settings of the Err object contain values that have not been cleared, those values become the values for your error.  When setting the number property to your own error code in an Automation object, you add your error code number to the constant vbObjectError.  For example, to generate the error number 1050, assign vbObjectError + 1050 to the number property.
  • 40. 40 What’s Next?  Regulars Expressions.  Methods and properties.  How to use the object and the object collections.  How to create complex patterns.

Editor's Notes

  1. Example: The fault which causes the Ariane 5 failure was a specification fault. For Ariane 5 software from Ariane 4 was reused, but this software does not match the requirements for Ariane 5. The validation of the specification against the requirements and the testing of the final software were not sufficient to detect the fault.
  2. Example: The fault which causes the Ariane 5 failure was a specification fault. For Ariane 5 software from Ariane 4 was reused, but this software does not match the requirements for Ariane 5. The validation of the specification against the requirements and the testing of the final software were not sufficient to detect the fault.
  3. Example: The fault which causes the Ariane 5 failure was a specification fault. For Ariane 5 software from Ariane 4 was reused, but this software does not match the requirements for Ariane 5. The validation of the specification against the requirements and the testing of the final software were not sufficient to detect the fault.
  4. Example: The fault which causes the Ariane 5 failure was a specification fault. For Ariane 5 software from Ariane 4 was reused, but this software does not match the requirements for Ariane 5. The validation of the specification against the requirements and the testing of the final software were not sufficient to detect the fault.
  5. Example: The fault which causes the Ariane 5 failure was a specification fault. For Ariane 5 software from Ariane 4 was reused, but this software does not match the requirements for Ariane 5. The validation of the specification against the requirements and the testing of the final software were not sufficient to detect the fault.
  6. There’s an episode of the Simpsons in which the family is driving along when an engine warning light begins flashing on the dashboard. “I’ll take care of that,” says Homer, who promptly grabs a piece of duct tape and tapes over the light so no one can see it. Problem solved
  7. Suppose you had a 100-line script and each line had been coded incorrectly. Theoretically, you could start that script and WSH would dutifully try to run each line. Each time it failed, WSH would simply skip to the next line. After all 100 lines had been tried, the script would gracefully end, just as though everything had worked perfectly. In truth, however, none of your 100 lines would have been executed.
  8. SCODE - A DWORD value that is used to return detailed information to the caller of an interface method or function. See also HRESULT.
  9. SCODE - A DWORD value that is used to return detailed information to the caller of an interface method or function. See also HRESULT.