Errors¶
Note
All Chapel programs automatically use
this module by default.
An explicit use
statement is not necessary.
This module contains several features related to error conditions and error handling:
Error
- the parent type for errors in Chapel that can be thrown and caught - as well as a few subclassescompilation diagnostic functions
compilerError
,compilerWarning
, andcompilerAssert
- class Error¶
Error
is the base class for errors- proc init()¶
Construct an Error
- proc init(msg: string)
Construct an
Error
with a message.
- proc message(): string¶
Override this method to provide an error message of type string in case the error is printed out or never caught.
- Return type
string
- class NilThrownError: Error¶
If a nil
Error
is thrown,NilThrownError
will be thrown instead.
- class NilClassError: Error¶
- class ClassCastError: Error¶
- class DecodeError: Error¶
A DecodeError is thrown if an attempt to create a string with non-UTF8 byte sequences are made at runtime. This includes calling the bytes.decode(decodePolicy.strict) method on a bytes with non-UTF8 byte sequences.
- class IllegalArgumentError: Error¶
- proc init()¶
- proc init(info: string)
- proc init(formal: string, info: string)
- class TaskErrors: Error¶
TaskErrors
stores multiple errors when they can come up. For example, acoforall
loop might throw errors from multiple tasks at the same time. These errors will be reported to the parent task at the end of thecoforall
in the form ofTaskErrors
.Note that errors thrown within a
coforall
,cobegin
, orforall
are represented as elements ofTaskErrors
. In the case of nesting, all errors will be stored in a singleTaskErrors
.Errors thrown in
begin
tasks will be reported within aTaskErrors
to the task that usessync
to wait for thosebegin
tasks.- proc init(err: unmanaged Error)¶
Create a
TaskErrors
containing only the passed error
- proc init()
Create a
TaskErrors
not containing any errors
- proc deinit()¶
- iter these() ref: owned nilable Error¶
Iterate over the errors contained in this
TaskErrors
. For examplevar taskErrors:TaskErrors = ...; for containedError in taskErrors { // Do something with the contained error }
Yields references to
owned Error?
so that one of the yielded errors might be re-thrown. Only yields values that are not storingnil
at the time of the call.
- proc first() ref: owned nilable Error¶
Returns the first non-nil error contained in this TaskErrors group
- override proc message(): string¶
Returns a string summarizing the errors contained in this
TaskErrors
. The summary is intended to be concise: it will not grow arbitrarily long if theTaskErrors
contains many errors.
- iter filter(type t) ref: owned nilable Error¶
Iterate over those errors contained that are the passed type or a subclass of that type.
Note that this iterator yields values of type
owned Error?
but only those that are non-nil and have dynamic typet
.
- proc contains(type t)¶
Returns true if this
TaskErrors
contains an error of the given type or a subclass of that type.
- proc assert(test: bool)¶
Assert that a boolean condition is true. If it is false, prints ‘assert failed’ and halts the program.
Note
In the current implementation, this assert never becomes a no-op. That is, using it will always incur execution-time checks.
- Arguments
test : bool – the boolean condition
- proc assert(test: bool, args ...?numArgs)
Assert that a boolean condition is true. If it is false, prints ‘assert failed - ‘ followed by all subsequent arguments, as though printed using
write()
.Note
In the current implementation, this assert never becomes a no-op. That is, using it will always incur execution-time checks.
- Arguments
test : bool – the boolean condition
args – other arguments to print
- proc compilerError(param msg: string ...?n)¶
Generate a compile-time error. The error text is a concatenation of the arguments.
- proc compilerWarning(param msg: string ...?n)¶
Generate a compile-time warning. The warning text is a concatenation of the arguments.
- proc compilerAssert(param test: bool)¶
Generate a compile-time error if the test argument is false.
- proc compilerAssert(param test: bool, param msg: string ...?n)
Generate a compile-time error if the test argument is false. The warning text is a concatenation of the string arguments.
- proc exit(status: int = 0)¶
Exit the program
- Arguments
status – The exit code for the program
- proc halt()¶
Prints an error message to stderr giving the location of the call to
halt
in the Chapel source, followed by the arguments to the call, if any, then exits the program.
- proc halt(msg: string)
Prints an error message to stderr giving the location of the call to
halt
in the Chapel source, followed by the arguments to the call, if any, then exits the program.
- proc halt(args ...?numArgs)
Prints an error message to stderr giving the location of the call to
halt
in the Chapel source, followed by the arguments to the call, if any, then exits the program.
- proc warning(msg: string)¶
Prints a warning to stderr giving the location of the call to
warning
in the Chapel source, followed by the argument(s) to the call.
- proc warning(args ...?numArgs)
Prints a warning to stderr giving the location of the call to
warning
in the Chapel source, followed by the argument(s) to the call.