Skip to content

Instantly share code, notes, and snippets.

@thecancerus
Created October 2, 2010 11:07
Show Gist options
  • Save thecancerus/607550 to your computer and use it in GitHub Desktop.
Save thecancerus/607550 to your computer and use it in GitHub Desktop.
<?php
class ExceptionHook
{
public function SetExceptionHandler()
{
set_exception_handler(array($this, 'HandleExceptions'));
}
public function HandleExceptions($exception)
{
$msg ='Exception of type \''.get_class($exception).'\' occurred with Message: '.$exception->getMessage().' in File '.$exception->getFile().' at Line '.$exception->getLine();
$msg .="\r\n Backtrace \r\n";
$msg .=$exception->getTraceAsString();
log_message('error', $msg, TRUE);
mail('[email protected]', 'An Exception Occurred', $msg, 'From: [email protected]');
}
<?php
class MY_Exceptions extends CI_Exceptions {
public function __construct()
{
parent::CI_Exceptions();
}
public function show_php_error($severity, $message, $filepath, $line)
{
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
$filepath = str_replace("\\", "/", $filepath);
// For safety reasons we do not show the full file path
if (FALSE !== strpos($filepath, '/'))
{
$x = explode('/', $filepath);
$filepath = $x[count($x)-2].'/'.end($x);
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include(APPPATH.'errors/error_php'.EXT);
$buffer = ob_get_contents();
ob_end_clean();
$msg = 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line;
log_message('error', $msg , TRUE);
mail('[email protected]', 'An Error Occurred', $msg, 'From: [email protected]');
}
}
@charlie-eth
Copy link

Did you ever find the solution to this @lomse
I have $config['subclass_prefix'] = 'MY_';

but still getting Class 'CI_Exceptions' not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment