Skip to content

Commit cb5ca36

Browse files
committed
Fixed another exception being reported without stack trace
This one happens when you use a default value on a ComVisible object, but assign an incorrect type to it.
1 parent 9681421 commit cb5ca36

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

ClearScript/Windows/WindowsScriptEngine.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,15 @@ private void ThrowHostException(Exception exception)
502502

503503
private void ThrowScriptError(Exception exception)
504504
{
505+
if (CurrentScriptFrame.ScriptError != null || CurrentScriptFrame.PendingScriptError != null)
506+
{
507+
// a script error was reported; the corresponding exception should be in the script frame
508+
ThrowScriptError(CurrentScriptFrame.ScriptError ?? CurrentScriptFrame.PendingScriptError);
509+
}
505510
var comException = exception as COMException;
506511
if (comException != null)
507512
{
508-
if (CurrentScriptFrame.ScriptError != null || CurrentScriptFrame.PendingScriptError != null)
509-
{
510-
// a script error was reported; the corresponding exception should be in the script frame
511-
ThrowScriptError(CurrentScriptFrame.ScriptError ?? CurrentScriptFrame.PendingScriptError);
512-
}
513-
else if (comException.ErrorCode == HResult.CLEARSCRIPT_E_HOSTEXCEPTION)
513+
if (comException.ErrorCode == HResult.CLEARSCRIPT_E_HOSTEXCEPTION)
514514
{
515515
// A host exception surrogate passed through the COM boundary; this happens
516516
// when some script engines are invoked via script item access rather than

ClearScriptTest/VBScriptEngineTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,28 @@ public void VBScriptEngine_ExceptionDetails()
490490
}
491491
}
492492

493+
[TestMethod, TestCategory("VBScriptEngine")]
494+
public void VBScriptEngine_ExceptionDetails2()
495+
{
496+
engine.AddHostObject("test", HostItemFlags.DirectAccess, new ComVisibleTestObject());
497+
engine.Execute("Sub Run\ntest = \"invalid type\"\nEnd Sub");
498+
try
499+
{
500+
engine.Invoke("Run");
501+
Assert.Fail("Expected failure");
502+
}
503+
catch (ScriptEngineException see)
504+
{
505+
Assert.AreEqual(
506+
"Class doesn't support Automation: 'test'\n at Run (Script [3]:1:0) -> test = \"invalid type\"",
507+
see.ErrorDetails, "Details message was wrong");
508+
}
509+
catch (Exception ex)
510+
{
511+
Assert.Fail("Wrong exception thrown: " + ex);
512+
}
513+
}
514+
493515
[TestMethod, TestCategory("VBScriptEngine")]
494516
public void VBScriptEngine_AccessContext_Private()
495517
{
@@ -3025,6 +3047,7 @@ public T Bogus<T>(T arg)
30253047
}
30263048

30273049
[ComVisible(true)]
3050+
[ClassInterface(ClassInterfaceType.AutoDual)]
30283051
public sealed class ComVisibleTestObject
30293052
{
30303053
public string Format(string format, object arg0 = null, object arg1 = null, object arg2 = null, object arg3 = null)
@@ -3036,6 +3059,8 @@ public T Bogus<T>(T arg)
30363059
{
30373060
return default(T);
30383061
}
3062+
3063+
public double Value { get; set; }
30393064
}
30403065

30413066
#endregion

0 commit comments

Comments
 (0)