Comments and blocks


For comments the usual XML comments <!-- --> may be used, or rem action:

<!-- this is a comment -->
<rem>This is also a comment, particularly useful 
if you need to insert --> into it</rem>


There are basic loops, blocks, and conditionals in XSharper. But with C# behind it, you can also use any construction C# allows.

The most primitive structure is sequence, which is just a sequence of commands:

		<print>This is line 1</print>
		<print>This is line 2</print>

Block is a special sequence, which can be followed by the standard try/catch/finally:

	<print>I'm about to open a file that may not exist</print>
		<readText from="c:\text.txt" outTo="txt" /> 
		<print>Exception ${=c.CurrentException.Message} has occurred</print>
		<throw />
		<print>This is executed no matter what</print>

Throwing exceptions

Exceptions may be thrown as

<throw class="IOException">Failed to open file</throw>

If class is not specified, exception of type ScriptUserException is thrown:

<throw>User error</throw>

There is a special exception type ScriptTerminateException which terminates the execution of the current script with error code. Unlike other exceptions, it is rethrown at the end of catch in blocks, making it similar to ThreadAbortedException in .NET:

<throw class="XS.ScriptTerminateException">5</throw>

This is useful for premature script termination, and there is shorter notation:

<exit exitCode="2" />

Error message can be produced too

<exit exitCode="-5">Failed to open file!</exit>