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

$this -> error -> set('Oops, something went wrong!', $logging, $fatal);
return $this -> error -> message();

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.

if($this->error->status() === true)
{
  //An error has occured
}

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

$this -> error -> reset();

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

$message = $this -> error -> get();

If no errors have been raised this will return an empty string.

 
error_module.txt · Last modified: 2013/09/12 22:49 (external edit)
[unknown button type]
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
WikiForumIRCBugs
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki