ILIAS  release_4-4 Revision
ilErrorHandling Class Reference

Error Handling & global info handling uses PEAR error class. More...

+ Inheritance diagram for ilErrorHandling:
+ Collaboration diagram for ilErrorHandling:

Public Member Functions

 ilErrorHandling ()
 Constructor public. More...
 
 getLastError ()
 
 errorHandler ($a_error_obj)
 defines what has to happen in case of error private More...
 
 getMessage ()
 
 setMessage ($a_message)
 
 appendMessage ($a_message)
 
 handleUncaughtException (Exception $e)
 Called for each uncaught exception. More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Static Public Member Functions

static _ilErrorWriter ($errno, $errstr, $errfile, $errline)
 This is used in Soap calls to write PHP error in ILIAS Logfile Not used yet!!! More...
 

Data Fields

 $DEBUG_ENV
 
 $FATAL
 
 $WARNING
 
 $MESSAGE
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Detailed Description

Error Handling & global info handling uses PEAR error class.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Sascha Hofmann shofm.nosp@m.ann@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$
Todo:
when an error occured and clicking the back button to return to previous page the referer-var in session is deleted -> server error

Definition at line 17 of file class.ilErrorHandling.php.

Member Function Documentation

◆ _ilErrorWriter()

static ilErrorHandling::_ilErrorWriter (   $errno,
  $errstr,
  $errfile,
  $errline 
)
static

This is used in Soap calls to write PHP error in ILIAS Logfile Not used yet!!!

public

Parameters

Definition at line 235 of file class.ilErrorHandling.php.

References $ilLog, and exit.

236  {
237  global $ilLog;
238 
239  switch($errno)
240  {
241  case E_USER_ERROR:
242  $ilLog->write('PHP errror: '.$errstr.'. FATAL error on line '.$errline.' in file '.$errfile);
243  unset($ilLog);
244  exit(1);
245 
246  case E_USER_WARNING:
247  $ilLog->write('PHP warning: ['.$errno.'] '.$errstr.' on line '.$errline.' in file '.$errfile);
248  break;
249 
250  }
251  return true;
252  }
exit
Definition: login.php:54

◆ appendMessage()

ilErrorHandling::appendMessage (   $a_message)

Definition at line 217 of file class.ilErrorHandling.php.

References getMessage().

218  {
219  if($this->getMessage())
220  {
221  $this->message .= "<br /> ";
222  }
223  $this->message .= $a_message;
224  }
+ Here is the call graph for this function:

◆ errorHandler()

ilErrorHandling::errorHandler (   $a_error_obj)

defines what has to happen in case of error private

Parameters
objectError

Definition at line 76 of file class.ilErrorHandling.php.

References $_POST, $_SESSION, $FATAL, $log, $MESSAGE, $WARNING, exit, and ilUtil\redirect().

77  {
78  global $log;
79 
80  // see bug 18499 (some calls to raiseError do not pass a code, which leads to security issues, if these calls
81  // are done due to permission checks)
82  if ($a_error_obj->getCode() == null)
83  {
84  $a_error_obj->code = $this->WARNING;
85  }
86 
87  $this->error_obj =& $a_error_obj;
88 //echo "-".$_SESSION["referer"]."-";
89  if ($_SESSION["failure"] && substr($a_error_obj->getMessage(), 0, 22) != "Cannot find this block")
90  {
91  $m = "Fatal Error: Called raise error two times.<br>".
92  "First error: ".$_SESSION["failure"].'<br>'.
93  "Last Error:". $a_error_obj->getMessage();
94  //return;
95  $log->logError($a_error_obj->getCode(), $m);
96  unset($_SESSION["failure"]);
97  die ($m);
98  }
99 
100  if (substr($a_error_obj->getMessage(), 0, 22) == "Cannot find this block")
101  {
102  if (DEVMODE == 1)
103  {
104  echo "<b>DEVMODE</b><br><br>";
105  echo "<b>Template Block not found.</b><br>";
106  echo "You used a template block in your code that is not available.<br>";
107  echo "Native Messge: <b>".$a_error_obj->getMessage()."</b><br>";
108  if (is_array($a_error_obj->backtrace))
109  {
110  echo "Backtrace:<br>";
111  foreach ($a_error_obj->backtrace as $b)
112  {
113  if ($b["function"] == "setCurrentBlock" &&
114  basename($b["file"]) != "class.ilTemplate.php")
115  {
116  echo "<b>";
117  }
118  echo "File: ".$b["file"].", ";
119  echo "Line: ".$b["line"].", ";
120  echo $b["function"]."()<br>";
121  if ($b["function"] == "setCurrentBlock" &&
122  basename($b["file"]) != "class.ilTemplate.php")
123  {
124  echo "</b>";
125  }
126  }
127  }
128  exit;
129  }
130  return;
131  }
132 
133  if (is_object($log) and $log->enabled == true)
134  {
135  $log->logError($a_error_obj->getCode(),$a_error_obj->getMessage());
136  }
137 
138 //echo $a_error_obj->getCode().":"; exit;
139  if ($a_error_obj->getCode() == $this->FATAL)
140  {
141  trigger_error(stripslashes($a_error_obj->getMessage()), E_USER_ERROR);
142  exit();
143  }
144 
145  if ($a_error_obj->getCode() == $this->WARNING)
146  {
147  if ($this->DEBUG_ENV)
148  {
149  $message = $a_error_obj->getMessage();
150  }
151  else
152  {
153  $message = "Under Construction";
154  }
155 
156  $_SESSION["failure"] = $message;
157 
158  if (!defined("ILIAS_MODULE"))
159  {
160  ilUtil::redirect("error.php");
161  }
162  else
163  {
164  ilUtil::redirect("../error.php");
165  }
166  }
167 
168  if ($a_error_obj->getCode() == $this->MESSAGE)
169  {
170  $_SESSION["failure"] = $a_error_obj->getMessage();
171  // save post vars to session in case of error
172  $_SESSION["error_post_vars"] = $_POST;
173 
174  if (empty($_SESSION["referer"]))
175  {
176  $dirname = dirname($_SERVER["PHP_SELF"]);
177  $ilurl = parse_url(ILIAS_HTTP_PATH);
178  $subdir = substr(strstr($dirname,$ilurl["path"]),strlen($ilurl["path"]));
179  $updir = "";
180 
181  if ($subdir)
182  {
183  $num_subdirs = substr_count($subdir,"/");
184 
185  for ($i=1;$i<=$num_subdirs;$i++)
186  {
187  $updir .= "../";
188  }
189  }
190  ilUtil::redirect($updir."index.php");
191  }
192 
193  /* #12104
194  check if already GET-Parameters exists in Referer-URI
195  if (substr($_SESSION["referer"],-4) == ".php")
196  {
197  $glue = "?";
198  }
199  else
200  {
201  // this did break permanent links (".html&")
202  $glue = "&";
203  }
204  */
205  ilUtil::redirect($_SESSION["referer"]);
206  }
207  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
static redirect($a_script)
http redirect to other script
+ Here is the call graph for this function:

◆ getLastError()

ilErrorHandling::getLastError ( )

Definition at line 66 of file class.ilErrorHandling.php.

67  {
68  return $this->error_obj;
69  }

◆ getMessage()

ilErrorHandling::getMessage ( )

Definition at line 209 of file class.ilErrorHandling.php.

Referenced by appendMessage().

210  {
211  return $this->message;
212  }
+ Here is the caller graph for this function:

◆ handleUncaughtException()

ilErrorHandling::handleUncaughtException ( Exception  $e)

Called for each uncaught exception.

Parameters
Exception$e

Definition at line 258 of file class.ilErrorHandling.php.

References PEAR\raiseError().

259  {
260  $error = $e->getMessage();
261  if (DEVMODE)
262  {
263  $error.= '<br /><br />';
264  $error.= nl2br($e->getTraceAsString());
265  }
266  $this->raiseError($error,$this->WARNING);
267  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

◆ ilErrorHandling()

ilErrorHandling::ilErrorHandling ( )

Constructor public.

Definition at line 51 of file class.ilErrorHandling.php.

References PEAR\PEAR().

52  {
53  $this->PEAR();
54 
55  // init vars
56  $this->DEBUG_ENV = true;
57  $this->FATAL = 1;
58  $this->WARNING = 2;
59  $this->MESSAGE = 3;
60 
61  $this->error_obj = false;
62 
63  set_exception_handler(array($this, 'handleUncaughtException'));
64  }
PEAR($error_class=null)
Constructor.
Definition: PEAR.php:170
+ Here is the call graph for this function:

◆ setMessage()

ilErrorHandling::setMessage (   $a_message)

Definition at line 213 of file class.ilErrorHandling.php.

214  {
215  $this->message = $a_message;
216  }

Field Documentation

◆ $DEBUG_ENV

ilErrorHandling::$DEBUG_ENV

Definition at line 24 of file class.ilErrorHandling.php.

◆ $FATAL

ilErrorHandling::$FATAL

Definition at line 31 of file class.ilErrorHandling.php.

Referenced by errorHandler().

◆ $MESSAGE

ilErrorHandling::$MESSAGE

Definition at line 45 of file class.ilErrorHandling.php.

Referenced by errorHandler().

◆ $WARNING

ilErrorHandling::$WARNING

Definition at line 38 of file class.ilErrorHandling.php.

Referenced by errorHandler().


The documentation for this class was generated from the following file: