public static function setExceptionHandler(ContainerInterface $container, string $context = '') /*: void*/
    {
        set_exception_handler(function(\Throwable $throwable) use ($container, $context) {
            $trace = $msg = null;
            try {
                $msg = rtrim(
                        get_class($throwable) . '(' . $throwable->getCode() . ')@' . $throwable->getFile() . ':'
                        . $throwable->getLine() . ': ' . addcslashes($throwable->getMessage(), "\0..\37"),
                        '.'
                    ) . '.';
                if ($container->has('inspect')) {
                    $trace = '' . $container->get('inspect')->trace($throwable);
                }
                if ($container->has('logger')) {
                    $container->get('logger')->error($trace ?? $throwable);
                }
            } catch (\Throwable $xcptn) {
                // Log original exception.
                if ($msg) {
                    error_log($msg);
                }
                // Log this exception handler's own exception.
                error_log(
                    get_class($xcptn) . '(' . $xcptn->getCode() . ')@' . $xcptn->getFile() . ':'
                    . $xcptn->getLine() . ': ' . addcslashes($xcptn->getMessage(), "\0..\37")
                );
            }
            switch ($context) {
                case 'http':
                    header('HTTP/1.1 500 Internal Server Error');
                    // Don't appear like PHP fatal error white-screen-of-death.
                    echo '<html><body><h1 style="font-family:sans-serif;color:darkblue">Internal Server Error</h1></body></html>';
                    exit;
                case 'cli':
                    echo "\033[01;31m[error]\033[0m " . ($trace ? ($msg . "\n- Check log.") : $throwable) . "\n";
                    break;
            }
        });
    }
public static function setExceptionHandler(ContainerInterface $container, string $context = '') /*: void*/
    {
        set_exception_handler(function(\Throwable $throwable) use ($container, $context) {
            $trace = $msg = null;
            try {
                $msg = rtrim(
                        get_class($throwable) . '(' . $throwable->getCode() . ')@' . $throwable->getFile() . ':'
                        . $throwable->getLine() . ': ' . addcslashes($throwable->getMessage(), "\0..\37"),
                        '.'
                    ) . '.';
                if ($container->has('inspect')) {
                    $trace = '' . $container->get('inspect')->trace($throwable);
                }
                if ($container->has('logger')) {
                    $container->get('logger')->error($trace ?? $throwable);
                }
            } catch (\Throwable $xcptn) {
                // Log original exception.
                if ($msg) {
                    error_log($msg);
                }
                // Log this exception handler's own exception.
                error_log(
                    get_class($xcptn) . '(' . $xcptn->getCode() . ')@' . $xcptn->getFile() . ':'
                    . $xcptn->getLine() . ': ' . addcslashes($xcptn->getMessage(), "\0..\37")
                );
            }
            switch ($context) {
                case 'http':
                    header('HTTP/1.1 500 Internal Server Error');
                    // Don't appear like PHP fatal error white-screen-of-death.
                    echo '<html><body><h1 style="font-family:sans-serif;color:darkblue">Internal Server Error</h1></body></html>';
                    exit;
                case 'cli':
                    echo "\033[01;31m[error]\033[0m " . ($trace ? ($msg . "\n- Check log.") : $throwable) . "\n";
                    break;
            }
        });
    }
public static function setExceptionHandler ( ContainerInterface $ container , string $ context = '' ) /*: void*/ { set_exception_handler ( function ( \ Throwable $ throwable ) use ( $ container , $ context ) { $ trace = $ msg = null ; try { $ msg = rtrim ( get_class ( $ throwable ) . '(' . $ throwable -> getCode ( ) . ')@' . $ throwable -> getFile ( ) . ':' . $ throwable -> getLine ( ) . ': ' . addcslashes ( $ throwable -> getMessage ( ) , "\0..\37" ) , '.' ) . '.' ; if ( $ container -> has ( 'inspect' ) ) { $ trace = '' . $ container -> get ( 'inspect' ) -> trace ( $ throwable ) ; } if ( $ container -> has ( 'logger' ) ) { $ container -> get ( 'logger' ) -> error ( $ trace ?? $ throwable ) ; } } catch ( \ Throwable $ xcptn ) { // Log original exception. if ( $ msg ) { error_log ( $ msg ) ; } // Log this exception handler's own exception. error_log ( get_class ( $ xcptn ) . '(' . $ xcptn -> getCode ( ) . ')@' . $ xcptn -> getFile ( ) . ':' . $ xcptn -> getLine ( ) . ': ' . addcslashes ( $ xcptn -> getMessage ( ) , "\0..\37" ) ) ; } switch ( $ context ) { case 'http' : header ( 'HTTP/1.1 500 Internal Server Error' ) ; // Don't appear like PHP fatal error white-screen-of-death. echo '<html><body><h1 style="font-family:sans-serif;color:darkblue">Internal Server Error</h1></body></html>' ; exit ; case 'cli' : echo "\033[01;31m[error]\033[0m " . ( $ trace ? ( $ msg . "\n- Check log." ) : $ throwable ) . "\n" ; break ; } } ) ; }
Attempts to log trace, or just exception details.

Behaviour by arg $context:
- http: sends 500 Internal Server Error and exits
- cli: prints error message
- empty or other: no behaviour apart from logging

@param ContainerInterface $container
@param string $context
Values: http|cli, or empty.
Attempts to log trace or just exception details .