我可以在 vbscript 中抛出错误吗? [英] Can I throw an error in vbscript?

查看:23
本文介绍了我可以在 vbscript 中抛出错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于用 C# 编程,它显然有一些非常强大的错误处理.现在我正在用 VBScript 做一个简短的项目.我已经阅读了有关使用On Error _______"和 Err 全局变量的 VBscript 错误处理的信息.

但是,有什么方法可以生成我自己的错误吗?例如,如果我的一个函数传递了错误类型的参数,我宁愿我的脚本在那时完全失败,然后尝试继续.

解决方案

是的,你可以.使用 Err.Raise 方法,例如:

Err.Raise 5 ' 无效的过程调用或参数

有关 VBScript 标准错误代码的列表,请参阅错误 (VBScript).>

I'm used to programing in C#, which obviously has some pretty robust error handling. Now I'm working on a short project in VBScript. I've read about the error handling with VBscript using "On Error _______" and the Err global variable.

However, is there some way I can generate my own errors? For example if one of my functions is passed the wrong type of parameter I'd rather my script just flat out fail at that point then try to continue.

解决方案

Yes, you can. Use the Err.Raise method, e.g.:

Err.Raise 5 ' Invalid procedure call or argument

For a list of VBScript's standard error codes, see Errors (VBScript).

这篇关于我可以在 vbscript 中抛出错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆