Throw an Exception

@param string $type
@param string $message

@throws \RuntimeException
@throws NotFoundHttpException
@throws AccessDeniedException
@throws \Exception
484518
public function throwException($message = '', $type = 'default')
    {
        switch ($type) {
            case 'access-denied':
                throw new AccessDeniedException($message);
            case 'not-found':
                throw new NotFoundHttpException($message);
            case 'runtime':
                throw new \RuntimeException($message);
            default:
                throw new \Exception($message);
        }
    }
1256633
public static function throwException($message, $messageStorage = null)
    {
        if ($messageStorage && ($storage = Mage::getSingleton($messageStorage))) {
            $storage->addError($message);
        }

        $exception = new Adyen_Payment_Exception($message);
        self::logException($exception);

        throw $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);
    }
142832
public function send($type, $id = null, $endpoint = null, $message = null)
        {
            if (!is_int($type) || $type > 8) {
                throw new Exception('Socketio::send() type parameter must be an integer strictly inferior to 9.');
            }

            $raw_message = $type . ':' . $id . ':' . $endpoint . ':' . $message;
            $payload = new Payload();
            $payload->setOpcode(Payload::OPCODE_TEXT)
                ->setMask(true)
                ->setPayload($raw_message);

            $encoded = $payload->encodePayload();

            fwrite($this->fd, $encoded);

            // wait 100ms before closing connexion
            usleep(100 * 1000);

            $this->stdout('debug', 'Sent '.$raw_message);

            return $this;
        }
313111
public void         add(Type type, String message, Throwable exception)
    {
        String          queueMessage = message;
        if ( (type == Type.ERROR) && (exception != null) )
        {
            queueMessage += " (" + getExceptionMessage(exception) + ")";
        }

        if ( type.addToUI() )
        {
            while ( queue.size() > windowSizeLines )  // NOTE: due to concurrency, this may make the queue shorter than MAX - that's OK (and in some cases longer)
            {
                queue.remove();
            }
            queue.add(new Message(queueMessage, type));
        }
        type.log(message, exception);
    }
725127
public function exceptionError($exception, $type = 'Exception')
    {
        $errorMsg = $exception->getMessage();
        $trace = $exception->getTrace();
        krsort($trace);
        $trace[] = ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'function' => 'break'];
        $phpMsg = [];
        foreach ($trace as $error) {
            if (!empty($error['function'])) {
                $fun = '';
                if (!empty($error['class'])) {
                    $fun .= $error['class'] . $error['type'];
                }
                $fun .= $error['function'] . '(';
                if (!empty($error['args'])) {
                    $mark = '';
                    foreach ($error['args'] as $arg) {
                        $fun .= $mark;
                        if (is_array($arg)) {
                            $fun .= 'Array';
                        } elseif (is_bool($arg)) {
                            $fun .= $arg ? 'true' : 'false';
                        } elseif (is_int($arg)) {
                            $fun .= $arg;
                        } elseif (is_float($arg)) {
                            $fun .= $arg;
                        } else {
                            $fun .= $this->clear($arg);
                        }
                        $mark = ', ';
                    }
                }
                $fun .= ')';
                $error['function'] = $fun;
            }
            if (!isset($error['line'])) {
                continue;
            }
            $phpMsg[] = ['file' => $error['file'], 'line' => $error['line'], 'function' => $error['function']];
        }
        $this->showError($type, $errorMsg, $phpMsg);
    }
840585
public function send($numbers, $message, $type = self::TYPE_DEFAULT_MESSAGE)
    {
        if (!in_array($type, $this->allowedTypes())) {
            throw new NotSupportedException("Message type \"$type\" doesn't support.");
        }

        if (empty($numbers) || (is_array($numbers) && count($numbers) === 0) || empty($message)) {
            throw new \InvalidArgumentException('For sending sms, please, set phone number and message');
        }

        $response = $this->_client->sendMessage([
            'phones' => $numbers,
            'message' => $message,
            'id' => $this->smsIdGenerator(),
        ]);

        if ($this->_logger instanceof LoggerInterface) {
            if (is_array($numbers)) {
                foreach ($numbers as $number) {
                    $this->_logger->setRecord([
                        'sms_id' => isset($response['id']) ? $response['id'] : '',
                        'phone' => $number,
                        'message' => $message,
                        'error' => isset($response['error']) ? $response['error'] : 0,
                    ]);
                }
            } else {
                $this->_logger->setRecord([
                    'sms_id' => isset($response['id']) ? $response['id'] : '',
                    'phone' => $numbers,
                    'message' => $message,
                    'error' => isset($response['error']) ? $response['error'] : 0,
                ]);
            }
        }

        return isset($response['id']) ? $response['id'] : false;
    }
1066346
private function triggerError($message) {
        $pdo = $this->pdoSupplier->getPDO();
        $mode = $pdo->getAttribute(\PDO::ATTR_ERRMODE);
        switch ($mode) {
            case \PDO::ERRMODE_WARNING:
                trigger_error($message, E_USER_ERROR);
                break;
            case \PDO::ERRMODE_EXCEPTION:
                throw new \RuntimeException($message);
                break;
            case \PDO::ERRMODE_SILENT:
            default:
                break;
        }
    }
954802
private function handleException(\Exception $exception, Request $request, $type)
    {
        $event = new GetResponseForExceptionEvent($this, $request, $type, $exception);
        $this->application->getEventDispatcher()->dispatch(KernelEvents::EXCEPTION, $event);

        return $event->getResponse();
    }
186409
protected function handleError($type, $message, $file, $line)
    {
        throw new ResourceException(sprintf(
            '%s: "%s" in %s on line %d',
            $type,
            $message,
            $file,
            $line
        ));
    }
1069594
protected function _throwIteratorException(
        $message = null,
        $code = null,
        RootException $previous = null
    ) {
        throw $this->_createIteratorException($message, $code, $previous, $this);
    }
540288
protected function _throwRendererException(
        $message = null,
        $code = null,
        RootException $previous = null
    ) {
        return $this->_createRendererException($message, $code, $previous, $this);
    }
107421
private function throwUnlessCorrectType($property, $value)
    {
        $typeUsedToBe = $this->getTypeUsedToBe($property);

        if ($typeUsedToBe !== "null") {
            $typeWantsToBe = $this->getTypeWantsToBe($value);

            if ($typeUsedToBe !== $typeWantsToBe) {
                throw new Exception();
            }
        }
    }
1371407
final public function setErrorMessage($message)
    {
        $this->errorMessage = (string) $message;

        if (empty($this->errorMessage)) {
            throw new \RuntimeException('Error message cannot be empty !');
        }

        return $this;
    }
856997
private static function logMessage($message, $type = null)
    {
        if (!self::$active) {
            return;
        }

        try {
            $file = fopen(self::$fileLocation, "a");

            if (!$file) {
                throw new Exception('Unable to open the input file');
            }

            $date_message = "{" . @date("Y/m/d H:i:s", time()) . "}";

            switch ($type) {
                case 'info':
                    $type_message = "[Info]";
                    break;
                case 'warning':
                    $type_message = "[Warning]";
                    break;
                case 'error':
                    $type_message = "[Error]";
                    break;
                case 'debug':
                default:
                    $type_message = "[Debug]";
                    break;
            }
            $str = "$date_message $type_message $message";
            fwrite($file, "$str \r\n");
            fclose($file);

        } catch (Exception $e) {
            echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " .
                self::$fileLocation;
        }

    }
285748
public function add($message, $type)
    {
        $this->messages[$type][] = $message;

        $this->getSessionBag()->set($type, $this->messages[$type]);
    }
1146412
public function outputCli( $message, $type )
    {
        if ( $type == 'normal' )
        {
            $this->output->outputLine( $message );
            $this->output->outputLine();
        }
        else if ( $type == 'warning' )
        {
            $this->output->outputLine( "Warning: ", 'warning' );
            $this->output->outputLine( $message);
            $this->output->outputLine();
        }
    }