[Ironruby-core] Can't run script after engine exception

Aaron Clauson lists at ruby-forum.com
Tue Feb 19 01:08:47 EST 2008


Tomas Matousek wrote:
> Could you sent a full repro containing the source code of both scripts 
> and the order of execution?
> 
> Tomas

I thought I'd made a mistake for a while as I was having real difficulty 
reapeating the problem. However I've found that it's a particular type 
of syntax error that causes the problem rather than any syntax error. 
The end statement missing on an if block is the culprit. Below is the 
code that illustrates the problem:

IScriptEnvironment scriptEnvironment = IronRuby.CreateRuntime();
IScriptEngine rubyengine = IronRuby.GetEngine(scriptEnvironment);

string goodScript =
@"
if true
 puts 'Ruby is cool'
end";

string badScript =
@"
if true
 puts 'Ruby is cool'
";

Console.WriteLine("Attempting run1 (good script).");
rubyengine.Runtime.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString(goodScript));

try
{
  Console.WriteLine("Attempting run2 (bad script).");
  rubyengine.Runtime.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString(badScript));
}
catch (Exception excp)
{
  Console.WriteLine(excp.GetType());
}

try
{
  Console.WriteLine("Attempting run3 (good script).");
  rubyengine.Runtime.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString(goodScript));
}
catch (Exception excp2)
{
  Console.WriteLine(excp2.GetType());
}

Output:

Attempting run1 (good script).
Ruby is cool
Attempting run2 (bad script).
Microsoft.Scripting.SyntaxErrorException
Attempting run3 (good script).
Microsoft.Scripting.SyntaxErrorException

Regards,

Aaron

-- 
Posted via http://www.ruby-forum.com/.


More information about the Ironruby-core mailing list