Error Trapping and Handling in
scripts
Overview
• Errors vs Exception
• Error Action
• Trapping exceptions
• Exiting the trap
• Following the trap scope
• Reviewing errors
• Capturing errors
• Adding traps to scrip t
Create a script n give computer name as
does not exits….This is called as error
We are adding a trap n executing but v c is
error but not trap…..can U tell me Y
The reason trap didn’t work
• Bcoz it is disabled by default n we need to
enable.
• By default it throws the error n not the
exception.
• The trap is = execption
• Lets enable it in next slide
Vallaaaahhh its woking
Use –EA parameter instead of at global
level
• Yeah That Red Color message is still dere….I
need it to go away
• Check the next screen
Valaaaahhhh I could c U all smiling
Its clearly going back at the top n closing
function…goes to trap…...n goes to next function
Add a Trap inside the function n Trap inside
functions runs n later continues in same function
• Lets learn something more….in the next slide
$Error contains all the error
You can also store that if any error occurs
store it to a variable
Summary
Review
• Errors vs Exception
• Error Action
• Trapping exceptions
• Exiting the trap
• Following the trap scope
• Reviewing errors
• Capturing errors
• Adding traps to scrip t