wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.WCMFException.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.WCMFException.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/util/class.Log.php");
20 
21 /**
22  * Global error function.
23  * Use this if you want to define a callback function and can not use WCMFWCMFException::throwEx().
24  */
25 function gError($message, $file='', $line='')
26 {
27  WCMFWCMFException::throwEx1($message, $file, $line);
28 }
29 /**
30  * @class WCMFException
31  * @ingroup core
32  * @brief Use the WCMFException class to handle errors.
33  * You need not instantiate a WCMFException object
34  * because the methods may be called like static
35  * class methods e.g.
36  * $translated = WCMFWCMFException::throwEx('error message', __FILE__, __LINE__)
37  *
38  * @author ingo herwig <ingo@wemove.com>
39  */
41 {
42  /**
43  * The throw() method may be used to output throw and terminate the programm.
44  * @note A global exception handling function with the same parameters may be defined in the global variable $EXCEPTION_HANDLER.
45  * @param message The exception message.
46  * @param file The current file (use __FILE__), recommended.
47  * @param line The current line (use __LINE__), recommended.
48  */
49  function throwEx($message, $file='', $line='')
50  {
51  global $EXCEPTION_HANDLER;
52  if (isset($EXCEPTION_HANDLER))
53  $EXCEPTION_HANDLER($message, $file, $line);
54  else
55  {
56  $str = '';
57  if ($file != '') $str = ' [ '.$file;
58  if ($line != '') $str .= ' '.$line;
59  if ($str != '') $str .= ' ]';
60  Log::fatal($str." ".$message."\n".WCMFException::getStackTrace(), __FILE__);
61  die('ERROR'.$str.': '.$message);
62  }
63  }
64  /**
65  * Get a stack trace.
66  * @return A string containing the stack trace.
67  */
68  function getStackTrace()
69  {
70  $vDebug = debug_backtrace();
71  $vFiles = array();
72  for ($i=0; $i<count($vDebug); $i++)
73  {
74  // skip the first one, since it's always this func
75  if ($i==0)
76  continue;
77  $aFile = $vDebug[$i];
78  $vFiles[] = ' -> '.$aFile['class'].$aFile['type'].$aFile['function'].' (called at '.basename($aFile['file']).':'.$aFile['line'].')';
79  }
80  return implode("\n", $vFiles);
81  }
82 }
83 ?>
throwEx($message, $file='', $line='')
gError($message, $file='', $line='')
Use the WCMFException class to handle errors. You need not instantiate a WCMFException object because...
fatal($message, $category)
Definition: class.Log.php:79