error_module

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
error_module [2008/03/03 07:02]
Blueeagle created
error_module [2020/09/12 01:30] (current)
Line 1: Line 1:
 +====== Introduction ======
 +The error module is intended as a tool to help uniform error handling in modules. The object of this class is to avoid returning arrays when errors are encountered.
 +
 +===== Setting an error =====
 +When something goes wrong in your module you can set the error like this
 +<code php>
 +$this -> error -> set('Oops, something went wrong!', $logging, $fatal);
 +return $this -> error -> message();
 +</code>
 +
 +When used with the base module and un-customised tell(), gc() and pgmsg() this will send a tell to the person invoking the command that the module has had an error and the message you defined.
 +
 +If $logging == true then an entry will be logged to the console (via $this -> bot -> log())
 +If $fatal == true then the bot will halt execution with an error code of 1. Do NOT use this unless the error is such that the bot should stop execution.
 +
 +===== Checking if an error has occured =====
 +You can check if an error has been raised by comparing the error objects status to a boolean.
 +<code php>
 +if($this->error->status() === true)
 +{
 +  //An error has occured
 +}
 +</code>
 +
 +===== Resetting the error object =====
 +This is particularly useful to do before the command is parsed so that a stale error does not affect the command
 +<code>
 +$this -> error -> reset();
 +</code>
 +
 +If you do not reset the error a previous error will be reported even if the command was executed successfully this time.
 +
 +===== Getting the error message =====
 +If you just want to get the message that was defined when raising the error without the color formatting of $this -> error -> message() you can call the get-function like this
 +<code php>
 +$message = $this -> error -> get();
 +</code>
 +If no errors have been raised this will return an empty string.