MSDN.WhiteKnight - Stack Overflow answers
Ответ на "Как вызвать ошибку понятную для COM?"
Answer 918847
У меня вот так работает
C#:
using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; namespace AxTest { [ProgId("AxTest.Class1")] [ClassInterface(ClassInterfaceType.AutoDual)] [Guid("177E405F-0C29-4FB1-B55A-D5324EDE1E97")] [ComVisible(true)] public class Class1 { public string Test(string x) { throw new Exception("Something bad happened!"); } } }
JS:
<html> <head> <title>ActiveX test</title> </head> <body> <script type="text/jscript"> try { var customObject = new ActiveXObject("AxTest.Class1"); var res = customObject.Test("Foo"); alert(res); } catch (ex) { alert("Exception: " + ex.message); } </script> </body> </html>
Судя по сообщению, у вас исключение завернуто в TargetInvocationException. Чтобы получить нормальное сообщение об ошибке, вам надо его перехватывать и пробрасывать как свое исключение. Потому что в JS не достать InnerException.
Content is retrieved from StackExchange API.
Auto-generated by ruso-archive tools.