Controlled throw for catch block

@param string $message
@param \Exception $exception
@param array $config
@return string
763025
static public function cThrow($message = null, \Exception $exception = null, $config = null)
    {

        if (!isset ($config ['display'])) {
            $config ['display'] = self::$displayTrace;
        }

        if (!isset ($config ['send'])) {
            $config ['send'] = self::$sendTrace;
        }

        if (!isset ($config ['write'])) {
            $config ['write'] = self::$writeTrace;
        }

        $retVal = '';

        if (empty ($message)) {
            $message = self::$standardErrorText;
        }

        $retVal .= self::displayBox($message);

        /**
         * if exception has been sent, try to display or send it
         */
        if (!empty ($exception)) {

            $errorFullText = self::formatExceptionMessage($exception);

            if ($config ['display']) {
                $retVal .= self::formatError($errorFullText);
            }

            if ($config ['send']) {
                self::send($errorFullText);
            }

            if ($config ['write']) {
                self::write($errorFullText);
            }

        }

        return $retVal;
    }
1142331
public static function throw_if($condition, $exception, ...$parameters)
    {
        if ($condition) {
            throw (\is_string($exception) ? new $exception(...$parameters) : $exception);
        }

        return $condition;
    }
9220
public function extract()
    {
        if (!isset($this->config['sourcePath'], $this->config['languages'])) {
            throw new Exception('The configuration must specify "sourcePath" and "languages".');
        }

        foreach ($this->config['sourcePath'] as $sourcePath) {
            if (!is_dir($sourcePath)) {
                throw new Exception("The source path {$sourcePath} is not a valid directory.");
            }
        }

        if (empty($this->config['format']) || !in_array($this->config['format'], ['php', 'po', 'db'])) {
            throw new Exception('Format should be either "php", "po" or "db".');
        }
        if (in_array($this->config['format'], ['php', 'po'])) {
            if (!isset($this->config['messagePath'])) {
                throw new Exception('The configuration file must specify "messagePath".');
            } elseif (!is_dir($this->config['messagePath'])) {
                throw new Exception("The message path {$this->config['messagePath']} is not a valid directory.");
            }
        }
        if (empty($this->config['languages'])) {
            throw new Exception("Languages cannot be empty.");
        }

        $files = [];
        foreach ( $this->config['sourcePath'] as $sourcePath ) {
            $files = array_merge(
                array_values($files),
                array_values(FileHelper::findFiles(realpath($sourcePath), $this->config))
            );
        }

        $messages = [];
        foreach ($files as $file) {
            $messages = array_merge_recursive($messages, $this->extractMessages($file, $this->config['translator']));
        }
        if (in_array($this->config['format'], ['php', 'po'])) {
            foreach ($this->config['languages'] as $language) {
                $dir = $this->config['messagePath'] . DIRECTORY_SEPARATOR . $language;
                if (!is_dir($dir)) {
                    @mkdir($dir);
                }
                if ($this->config['format'] === 'po') {
                    $catalog = isset($this->config['catalog']) ? $this->config['catalog'] : 'messages';
                    return $this->saveMessagesToPO($messages, $dir, $this->config['overwrite'], $this->config['removeUnused'], $this->config['sort'], $catalog);
                } else {
                    return $this->saveMessagesToPHP($messages, $dir, $this->config['overwrite'], $this->config['removeUnused'], $this->config['sort']);
                }
            }
        } elseif ($this->config['format'] === 'db') {
            $db = \Yii::$app->get(isset($this->config['db']) ? $this->config['db'] : 'db');
            if (!$db instanceof \yii\db\Connection) {
                throw new Exception('The "db" option must refer to a valid database application component.');
            }
            $sourceMessageTable = isset($this->config['sourceMessageTable']) ? $this->config['sourceMessageTable'] : '{{%source_message}}';
            $messageTable = isset($this->config['messageTable']) ? $this->config['messageTable'] : '{{%message}}';
            return $this->saveMessagesToDb(
                $messages,
                $db,
                $sourceMessageTable,
                $messageTable,
                $this->config['removeUnused'],
                $this->config['languages']
            );
        }
    }
1260024
public function exceptionHandler(Exception $exception)
    {
        $this->logger->addError($exception->getMessage(), array($exception->getFile(), $exception->getLine()));
        exit(-1);
    }
856773
public function handleException(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
    {
        if ($level = $this->shouldLog('error')) {
            $this->logError($exception, $level);
        }

        return $this->handler->handleException($request, $response, $exception);
    }
1247108
public function catchException($exception)
    {
        if (in_array(get_class($exception), $this->config->getExcludeExceptions())) {
            return;
        }

        try {
            $this->send(
                Formatter::make($exception, $this->config)->toArray()
            );
        } catch (Exception $exception) {
            error_log('AfterBug Error: Couldn\'t notify. '.$exception->getMessage());
        }
    }
909255
private function logException($message, $exception)
    {
        return $this->app['logger.system']->error(
            $message . ': ' . $exception->getMessage(),
            ['event' => 'exception', 'exception' => $exception]
        );
    }
889952
private function _failOnErrorAction(Exception $exception = null, $message = '', $level = Project::MSG_INFO)
    {
        if ($this->_failonerror) {
            throw new BuildException(
                $exception !== null ? $exception : $message,
                $this->getLocation()
            );
        } else {
            $this->log(
                $exception !== null && $message === '' ? $exception->getMessage() : $message,
                $level
            );
        }
    }
599953
private function createAndDispatchTransportException($message, AnyException $exception)
    {
        $transportException = new Swift_TransportException($message, 0, $exception);

        if ($event = $this->eventDispatcher->createTransportExceptionEvent($this, $transportException)) {
            $this->eventDispatcher->dispatchEvent($event, 'exceptionThrown');
        }

        return $transportException;
    }
1098703
public function handleException(Exception $exception) {
        // untangle message from php7errorexception
        $message = $exception instanceof PHP7ErrorException ? $exception->getError()->getMessage(): $exception->getMessage();

        // send a debug mail with the exception
        if(!$this->debug && !in_array(get_class($exception), $this->_skipExceptions))
            $this->_email('CLI Exception', Misc::dump($exception, $message, true));

        // continue with exception handle logic
        parent::handleException($exception);
    }
872822
public function exception($message = 'Undefined Exception', $code = null)
    {
        $arg = [
            $message,
            'tags'     => implode(', ', array_keys($this->tags)),
            'template' => $this->template,
        ];

        if ($this->source) {
            $arg['source'] = $this->source;
        }

        return new Exception($arg, $code);
    }
24918
private function log($message, $party = null, $exception = false) {
		if (!$this->config->getDebugMode()) return;
		
		if (!$party) {
			$party = $message instanceof SmtpResponse ? 'server' : 'client';
		}
		// @todo: add logger possibility
		$eol = self::EOL;
		echo "SMTP " . strtoupper($party) . ":{$eol}{$message}{$eol}";
		
	}
1216805
public function configureException(ContainerBuilder $container, array $config)
    {
        // retrieve available filters
        $filters = [];
        foreach ($config['exception']['filters'] as $name => $filter) {
            $filters[$name] = $filter;
        }

        // retrieve available renderers
        $renderers = [];
        foreach ($config['exception']['renderers'] as $name => $renderer) {
            $renderers[$name] = $renderer;
        }

        // retrieve block customization
        $blockFilters = [];
        $blockRenderers = [];
        foreach ($config['blocks'] as $service => $settings) {
            if (isset($settings['exception'], $settings['exception']['filter'])) {
                $blockFilters[$service] = $settings['exception']['filter'];
            }
            if (isset($settings['exception'], $settings['exception']['renderer'])) {
                $blockRenderers[$service] = $settings['exception']['renderer'];
            }
        }

        $definition = $container->getDefinition('sonata.block.exception.strategy.manager');
        $definition->replaceArgument(1, $filters);
        $definition->replaceArgument(2, $renderers);
        $definition->replaceArgument(3, $blockFilters);
        $definition->replaceArgument(4, $blockRenderers);

        // retrieve default values
        $defaultFilter = $config['exception']['default']['filter'];
        $defaultRenderer = $config['exception']['default']['renderer'];
        $definition->addMethodCall('setDefaultFilter', [$defaultFilter]);
        $definition->addMethodCall('setDefaultRenderer', [$defaultRenderer]);
    }
137435
public static function exception_handler(\Exception $exception) {
		global $CFG, $USR;
		$errcode = $exception->getCode();
		$errmsg = $exception->getMessage();
		$errcodelabel = ($exception instanceof \pdyn\base\Exception)
			? $exception->get_string_from_code($errcode)
			: static::getinternalerrorlabel($errcode);
		if (\pdyn\base\Utils::is_cli_env() === true) {
			echo 'APP ERROR: '.$errcodelabel.': '.$errmsg."\n";
		} else {
			// Atlas exceptions' error codes are HTTP status codes, so send one.
			if (($exception instanceof \pdyn\base\Exception) && !empty($errcode) && !headers_sent()) {
				\pdyn\httputils\Utils::send_status_code($errcode, '', false);
			} else {
				\pdyn\httputils\Utils::send_status_code(500, '', false);
			}
			$LOG = new \pdyn\log\Logger($CFG->log_general);
			$LOG->error($errcodelabel.': '.$exception);
			if (isset($_GET['ajax'])) {
				header('Content-type: application/json');
				echo json_encode(['result' => 'fail', 'msg' => $errcodelabel.': '.$errmsg]);
			} else {
				$debugmode = (!empty($CFG) && (bool)$CFG->get('core', 'debugmode', false) === true) ? true : false;
				$isadmin = (!empty($USR) && $USR->is_admin === true) ? true : false;
				$backtrace = ($isadmin === true || $debugmode === true)	? static::format_backtrace($exception->getTrace()) : null;
				static::write_error_html($errcodelabel, $errmsg, $errcode, $backtrace);
			}
		}
		die();
	}
527551
public function handleException(Exception $exception)
    {
        try {
            while (ob_get_level()) {
                ob_end_clean();
            }

            $code = 500;
            if (is_subclass_of($exception, 'Rad\\Core\\Exception\\BaseNetworkException')) {
                $code = $exception->getCode();
            }

            http_response_code($code);
            echo $this->handler->handle($exception);

            return;
        } catch (Exception $e) {
            $message = sprintf(
                "[%s] %s\n%s",
                get_class($e),
                $e->getMessage(),
                $e->getTraceAsString()
            );

            trigger_error($message, E_USER_ERROR);
        }
    }
803915
public function encodeException(\Exception $exception)
	{
		$string = $this->encoder->encodeException($exception);

		try {
			return $this->encrypt($string);
		}
		catch (\Exception $e) {
			if ($this->plainExceptions) {
				return $string;
			}
			throw $e;
		}
	}
760532
public function err( $message )
	{
		$ex = new Exception();
		echo $ex->getTraceAsString();

		if ( ! $this->log ) return;
		return $this->log->err( $message );
	}