PHP code example of joungkyun / myexception

1. Go to this page and download the library: Download joungkyun/myexception library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joungkyun / myexception example snippets



f you want to manage E_ERROR with myException
#function fatal_error ($dump) {
#   echo '::: Fatal Messages' . PHP_EOL;
#   print_r ($dump);
#}
#error_reporting (E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_ERROR);
#register_shutdown_function('myException::myShutdownHandler', 'fatal_error');

# If you want to manage all Warning/Error except E_ERROR, uncomment follow line.
set_error_handler('myException::myErrorHandler');

class myEX {
    function foo () {
        try {
            if ( ! function_exists ('mysql_connect') )
                throw new myException ('Unsupported mysql_connect function', E_USER_ERROR);

			// for this warning, need set_error_handler
            $c = mysql_connect ();
        } catch ( Exception $e ) {
            throw new myException ($e->getMessage (), $e->getCode (), $e);
        }
    }
}

$m = new myEX;

try {
    $m->foo ();
} catch ( Exception $e ) {
    echo $e->Message () . "\n";
    print_r ($e->TraceAsArray ()) . "\n";
    $e->finalize ();
}