我可以让vbscript显示友好的错误消息吗?

我可以让vbscript显示友好的错误消息吗?,vbscript,Vbscript,我正在使用vbscript安装网络打印机,如果队列不存在或打印机服务器不可用,我想显示一个友好错误,我可以使用vbscript执行此操作吗?我的代码如下 Dim net Set net = CreateObject("WScript.Network") net.AddWindowsPrinterConnection "\\printsrv\HPLaser23" net.SetDefaultPrinter "\\printsrv\HPLaser23" 非常感谢你的帮助 Steven添加行: O

我正在使用vbscript安装网络打印机,如果队列不存在或打印机服务器不可用,我想显示一个友好错误,我可以使用vbscript执行此操作吗?我的代码如下

Dim net
Set net = CreateObject("WScript.Network") 
net.AddWindowsPrinterConnection "\\printsrv\HPLaser23"
net.SetDefaultPrinter "\\printsrv\HPLaser23"
非常感谢你的帮助

Steven

添加行:

On Error Resume Next ' the script will "ignore" any errors 
在你的代码之前

然后做一个:

if  Err.Number <> 0  then 
     ' report error in some way
end if
On Error GoTo 0 ' this will reset the error handling to normal
如果错误号为0,则
'以某种方式报告错误
如果结束
在错误转到“0”时,这会将错误处理重置为正常
在你的代码之后

通常情况下,最好尽量将错误恢复下一步的
和错误返回0的
之间的代码行数保持在尽可能少的范围内,因为忽略错误很少有好处