LOGIN  |  REGISTER
Smart Living Made Brilliant!
CASTLEOS FORUM

HomeScripting

A forum for information about scripting with CastleOS. Get samples, suggestions, and other help here

Error handling Messages in this topic - RSS

Scott Goffman
Scott Goffman
Posts: 111


11/14/2016
Scott Goffman
Scott Goffman
Posts: 111
It's been a while since I've done any CastleOS scripting, but I'm pretty sure that I used to be able to use Try/Catch statements for error handling (and getting useful debugging info). But in the latest Core Service betas, Try/Catch doesn't seem to work anymore; if there's any error in a script, it just silently fails.

For example, this simple test script:

using System;
using CastleOSCoreService;
using System.Diagnostics;
using System.Net;

public class TestScript
{
public void Main(string[] args)
{
try
{
ThisIsNotARealFunction();

}
catch (Exception e)
{
File.WriteAllText("C:\\ScriptError.txt", e.ToString());
}
}
}


Should throw a NullRef exception to the text file, but nothing is output. Did something change? Is there a better way to catch script errors?

(I also tried outputting errors to the System EventLog, but same lack of results now.)


-Scott
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3390


11/14/2016
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3390
That would be working, if it's not, then it's not catching the error and the "silent fail" is likely down the chain. You can also use the built in scripting LogError method to write errors to the CastleOS error log.

Also, keep in mind you can now write C# plugins too, which may be a better avenue than scripts for many things.
0 link