Generate an error condition
error (String_Type msg
The error
function generates a S-lang error condition causing
the interpreter to start unwinding to top-level. It takes a single
string parameter which is displayed on the stderr output device.
The error condition may be cleared via an ERROR_BLOCK
with the
_clear_error
function. Consult A Guide to the S-Lang Language for more
information.
define add_txt_extension (file)
{
if (typeof (file) != String_Type)
error ("add_extension: parameter must be a string");
file += ".txt";
return file;
}
verror, _clear_error, message
Print a string onto the message device
message (String_Type s
The message
function will print the string specified by
s
onto the message device.
define print_current_time ()
{
message (time ());
}
The message device will depend upon the application. For example,
the output message device for the jed
editor correspond to the
line at the bottom of the display window. The default message
device is the standard output device.
vmessage, sprintf, error
Generate a usage error
usage (String_Type msg)
The usage
function generates a usage exception and displays
msg
to the message device.
Suppose that some function plot
plots an array of x
and
y
values. The such a function could be written to issue a
usage message if the wrong number of arguments were passed:
define plot ()
{
variable x, y;
if (_NARGS != 2)
usage ("plot (x, y)");
(x, y) = ();
% Now do the hard part
.
.
}
error, message
Generate an error condition
verror (String_Type fmt, ...)
The verror
function performs the same role as the error
function. The only difference is that instead of a single string
argument, verror
takes a sprintf style argument list.
define open_file (file)
{
variable fp;
fp = fopen (file, "r");
if (fp == NULL) verror ("Unable to open %s", file);
return fp;
}
In the current implementation, strictly speaking, the verror
function is not an intrinsic function. Rather it is a predefined
S-lang function using a combination of Sprintf
and
error
.
error, Sprintf, vmessage
Print a formatted string onto the message device
vmessage (String_Type fmt, ...)
The vmessage
function formats a sprintf style argument list
and displays the resulting string onto the message device.
In the current implementation, strictly speaking, the vmessage
function is not an intrinsic function. Rather it is a predefined
S-lang function using a combination of Sprintf
and
message
.
message, Sprintf, verror