Handling errors

Errors are reported by Cowl via return values (such as cowl_ret), or by returning NULL on allocation errors. Sometimes this may not be enough, such as when reading ontology documents. In these cases, Cowl supports a more detailed error reporting mechanism via the CowlError type, whose instances are returned by functions such as cowl_reader_last_error().

struct CowlError

Error information.

Public Members

cowl_ret code

Error code.

ulib_uint byte

Byte offset where the error occurred, or 0 if not available.

ulib_uint line

Line number where the error occurred, or 0 if not available.

ulib_uint col

Column number where the error occurred, or 0 if not available.

UString message

Error message, or ustring_null if not available.

CowlError cowl_error(cowl_ret code, char const *fmt, ...)

Creates a new error with the specified code and message.

Note

The returned object must be destroyed by calling cowl_error_deinit.

Parameters:
  • code – Error code.

  • fmt – Error message format string, or NULL for no message.

  • ... – Format string arguments.

Returns:

Error object.

CowlError cowl_error_code(cowl_ret code)

Creates a new error with the specified code and no message.

Note

The returned object must be destroyed by calling cowl_error_deinit.

Parameters:
  • code – Error code.

Returns:

Error object.

void cowl_error_deinit(CowlError *error)

Deinitializes the error.

Parameters:
  • error – The error.

bool cowl_error_has_message(CowlError const *error)

Checks if the error has a message.

Parameters:
  • error – The error.

Returns:

True if the error has a message, false otherwise.

bool cowl_error_has_loc(CowlError const *error)

Checks if the error has a location.

Parameters:
  • error – The error.

Returns:

True if the error has a location, false otherwise.

UString cowl_error_to_string(CowlError const *error)

Converts the error to a string.

See also

cowl_write_error

Note

The returned object must be destroyed by calling ustring_deinit.

Parameters:
  • error – The error.

Returns:

String representation of the error.