Module: Error

Support for error handling.

This module helps to handle errors. In particular, it enables routines to return a syserr - encoding an error state - and then contains routines that can be provided a syserr in order to print out a useful error message.

This module defines the type syserr, which can encode an error code or an error message. This type can be returned from routines generating an error.

The IO module uses these routines in a way that supports error inspection and also rapid prototyping. Most routines in the IO module have two forms. In one form, an error (of type syserr) is returned in an out error argument. In the second form, no error is returned, and instead the task will halt with a fatal error if an error is encountered.

proc ioerror(error: syserr, msg: string)

Halt with a useful message if there was an error. Do nothing if the error argument does not indicate an error occured. The error message printed when halting will describe the error passed and msg will be appended to it.

Arguments:
  • error – the error object
  • msg – extra information to print after the error description
proc ioerror(error: syserr, msg: string, path: string)

Halt with a useful message if there was an error. Do nothing if the error argument does not indicate an error occured. The error message printed when halting will describe the error passed and msg will be appended to it, along with the path related to the error (for example, the path to a file which could not be opened).

Arguments:
  • error – the error object
  • msg – extra information to print after the error description
  • path – a path to print out that is related to the error
proc ioerror(error: syserr, msg: string, path: string, offset: int(64))

Halt with a useful message if there was an error. Do nothing if the error argument does not indicate an error occured. The error message printed when halting will describe the error passed and msg will be appended to it, along with the path and file offset related to the error. For example, this routine might indicate a file format error at a particular location.

Arguments:
  • error – the error object
  • msg – extra information to print after the error description
  • path – a path to print out that is related to the error
  • offset – an offset to print out that is related to the error
proc ioerror(errstr: string, msg: string, path: string, offset: int(64))

Halt with a useful message. Instead of an error argument, this routine takes in an error string to report. The error message printed when halting will describe the error passed and msg will be appended to it, along with the path and file offset related to the error. For example, this routine might indicate a file format error at a particular location.

This routine .

Arguments:
  • errstr – the error string
  • msg – extra information to print after the error description
  • path – a path to print out that is related to the error
  • offset – an offset to print out that is related to the error
proc errorToString(error: syserr): string

Convert a syserr error code to a human-readable string describing that error.

Arguments:errstr – the error string
Returns:a string describing the error