//
stai leggendo...
domanda

Scripting games–ErrorActionPreference

Richard Siddaway's Blog

I’ve seen a lot of this type of thing in events 1 and 2

$ErrorPref = $ErrorActionPreference
$ErrorActionPreference = “Stop”

 

Don’t

The default for $ErrorActionPreference is Continue.  This means that the error message is shown and the cmdlet attempts to continue. The possible values (from about_Preference_Variables)

Stop:               Displays the error message and stops  executing.

Inquire:            Displays the error message and asks you  whether you want to continue.

Continue:           Displays the error message and continues executing.
(Default)          

SilentlyContinue:   No effect. The error message is not displayed and execution continues without interruption.

This preference variable only affects non-terminating errors. A terminating error will still stop processing.  Using

$ErrorActionPreference = “Stop”

effectively turns all errors in to terminating errors.

There are times when you want to stop processing and deal with the error such as

try {

some cmdlet

}

catch {

do something

}

In this case use –ErrorAction Stop  on…

View original post 21 altre parole

Annunci

Discussione

Non c'è ancora nessun commento.

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger hanno fatto clic su Mi Piace per questo: