Skip to content

Error Handling

Tom Sherman edited this page Mar 8, 2017 · 7 revisions

Example

error vs print

There are several advantages to calling error or rather THROW_ERROR over using a simple print statement.

  • The last error will always be printed, even if the stream crashed due to failed memory allocation.
  • THROW_ERROR allows you to set an error code
  • THROW_ERROR automatically includes file name and line number with the message

Error Codes

THROW_ERROR allows you to send an error code along with the error message. error.h allows for up to 32 unique error codes to be active at the same time. You can check if an error code has been throw with ERROR_THROWN(code). It is recommended you rename error codes to something more specific, i.e.

#define MEM_ALLOC_ERROR     ERR_1

Clone this wiki locally