Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress errors for the whole script

I am want to suppress all the errors that could appear in my VBS logon script.

Can I surround the WHOLE 500 lines script with :

On Error Resume Next

'[... whole script (~500 lines of code) ...]

On Error GoTo 0
like image 685
Jonathan Rioux Avatar asked Nov 29 '12 14:11

Jonathan Rioux


People also ask

How do I supress an error in Unix?

1> /dev/null throw away stdout. 2> /dev/null throw away stderr. &> /dev/null throw away both stdout and stderr.

How do you stop error messages in bash script?

If you are looking to suppress or hide all the output of a bash shell script from Linux command line as well as from the crontab then you can simply redirect all the output to a file known as /dev/null . This file is known as Black Hole which will engulf everything you give without complaining.

How do I suppress errors in PowerShell script?

Error action The ErrorAction switch lets you tell PowerShell what to do if the cmdlet produces an error. If your goal is to suppress an error message and make it seem as though nothing has happened, then the error action of choice is SilentlyContinue.


1 Answers

You can do it - even without the OEG0 line - but you shouldn't, because the script will continue to execute lines i ... last, even if an error in line i-1 invalidates all your assumptions about necessary pre-conditions of the actions in those lines. Your strategy is comparable to driving with your eyes shut to avoid being dazzled by the headlights of other cars.

If you can't do locally resticted error handling for selected actions -

...
On Error Resume Next
  risky_action
  save Err
On Error GoTo 0
If ErrorOccurred Then
   something sensible
   If can't continue Then
      WScript.Quit 4711
   End If
End If
...

try to get away with

Sub Main()
  ... you 500 lines ...
End Sub 

On Error Resume Next
  Main
  If Err.Number Then
     WScript.Echo "aborted"
     WScript.Quit 4711
  End If

This approach makes sure that the lines after an error won't be executed.

like image 172
Ekkehard.Horner Avatar answered Nov 19 '22 17:11

Ekkehard.Horner