I have a c# com object that exposes several methods.
This com object is to be used in vbscripts as well as vba scripts.
In my application error handling is done by throwing different types of custom exceptions. The problem is that when theses exceptions are caught by the vbscript the type of the exception is unknown.
Therefore I would need Err.Number to determine what kind of exception was thrown. Unfortunately I have not been able to figure out how that works.
For some reason ExternalException does not do the trick.
Simple example:
COM object:
Expand|Select|Wrap|Line Numbers
- [ComVisible(true)]
- public class MyClass
- {
- public void Test()
- {
- throw new MyTimeoutException() //MyTimeoutException somehow sets Err.Code to 123
- }
- }
Expand|Select|Wrap|Line Numbers
- Dim k
- set k = CreateObject("ns.MyClass")
- on error resume next
- k.Test
- if err.number = 123 then
- MsgBox "Crap. Operation timed out."
- end if
- set k = nothing
Kevin