我们正在开发基于 ASP 的 Web 服务器,以在 WIN CE 设备上运行。 ASP 页使用 COM 组件来执行服务器端操作。
我们对错误处理有一些疑问。我们的疑问是,
从 COM 组件向 ASP 页提供错误信息的最佳方法是什么?我们正在使用 VBScript 编写 ASP
如果我们要显示从 COM 服务器收到的特定错误消息,例如“连接超时”,从 COM 传递错误消息的最佳机制是什么?
我们在哪里可以找到有关错误处理的更多信息?
我们是 VBScript 新手,在网上找不到有关该主题的太多信息
We are developing ASP based web server to run on a WIN CE device. The ASP pages use a COM component for performing the server side operations.
We have a couple of doubts about the error handling. Our doubts are
What is the best method for giving error information from a COM component to the ASP page? We are using VBScript for writing ASP
If we are going to display specific error messages like ‘Connection Timeout’ received from the COM server, what is the best mechanism to pass the error message from COM?
Where can we find more information about error handling?
We are new to VBScript and we could not find much information about the topic in the net
发布评论
评论(2)
COM 对象方法通常返回一个 HRESULT,其中包含失败时的错误代码。您可以尝试通过读取属性 错误编号。
COM object methods generally return an HRESULT, which contains an error code in case of failure. You can try to get this value in VB.Script by reading the property Err.Number.
这是一种可能适合您的方法。
将对 COM 对象的调用放入子函数或函数中,以便您可以在该范围内使用“On Error Resume Next”。 (除非您在任何地方都执行
On Error Resume Next
,只要您进行大量错误检查,这也可能没问题。)每当您执行任何可能引发错误的操作(例如调用 COM 对象)时,请检查错误并相应地进行处理。例如,如果您只想默默地记录错误,您可以调用与此类似的子程序:
或者退出并向用户显示错误信息。
Here is one approach that may work for you.
Put your call to the COM object inside a sub or function, so that you can use 'On Error Resume Next' just within that scope. (Unless you are doing
On Error Resume Next
everywhere, which is also possibly OK, as long as you are doing lots of error checking.)Whenever you do anything that might throw an error, e.g. calling your COM object, check for an error and handle it accordingly. For example, in the case where you just want to silently log the error you could call a sub similar to this one:
Or alternatively, quit, and display the Error info to the user.