Throw an exception based on API configuration

@param \Cake\Event\Event $Event Event
@param array $exceptionConfig Exception config
@return void
@throws \Exception
324550
protected function _exceptionResponse(Event $Event, $exceptionConfig)
    {
        $exceptionConfig = array_merge($this->getConfig('exception'), $exceptionConfig);

        $class = $exceptionConfig['class'];

        if ($exceptionConfig['type'] === 'validate') {
            $exception = new $class($Event->getSubject()->entity);
            throw $exception;
        }

        $exception = new $class($exceptionConfig['message'], $exceptionConfig['code']);
        throw $exception;
    }
31123
public function onRequestException(Event $event)
    {
        if (!$event['exception'] instanceof CurlException) {
            return;
        }

        $request = $event['request'];
        if (!$this->canCache->canCacheRequest($request)) {
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $response->setHeader('Age', time() - strtotime($response->getDate() ? : 'now'));
            if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
                return;
            }
            $request->getParams()->set('cache.hit', 'error');
            $request->setResponse($response);
            $this->addResponseHeaders($request, $response);
            $event->stopPropagation();
        }
    }
476348
public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt)
    {
        if ($this->bag->get('pd_mailer.logger_active')) {
            // Update Data
            $this->log->setStatus(\Swift_Events_SendEvent::RESULT_FAILED);
            $this->log->addException($evt->getException()->getMessage() . PHP_EOL);

            // Update
            $this->entityManager->persist($this->log);
            $this->entityManager->flush();
        }
    }
317615
static public function setConfig($config)
        {
            if (!is_array($config)) {
                throw new Exception("Config must be an array.");
            }

            foreach ($config as $k => $v) {
                self::$_config[$k] = $v;
            }
        }
401728
protected function runConfig(array $config, Configuration $parent = null)
  {
    try
    {
      $config = $this->validateConfiguration($config);
      foreach ($config as $key => $settings)
      {
        $this->configuration[$key] = new Configuration($key);
        $this->configuration[$key]->setParent($parent);
        $this->setBaseConfiguration($settings, $key);
        $this->setBaseOptions($settings, $key);
        $this->{'set' . ucfirst($this->configuration[$key]->getType()) . 'Options'}($settings, $key);
        $this->createChildren($settings, $key);
        $this->setEventConfiguration($settings, $key);

        $this->dispatcher->dispatch(
          TransformerEvents::AFTER_CONFIGURATION,
          new ConfigurationEvent($this->configuration[$key])
        );
      }

      return $this->configuration;
    }
    catch (\Exception $e)
    {
      $this->dispatcher->dispatch(TransformerEvents::ON_EXCEPTION, new ExceptionEvent($e));
      throw new TransformerException($e->getMessage() . ' --- ' . $e->getFile() . ': ' . $e->getLine());
    }
  }
517179
public function eventTypeConfig()
    {
        $this->request->allowMethod(['post', 'put', 'patch']);

        $response = [
            'success' => false,
            'data' => [],
            'errors' => [],
        ];

        $data = $this->request->getData();

        try {
            $config = ObjectFactory::getConfig(null, 'Event', $data['event_type']);

            if (!empty($config)) {
                $response['success'] = true;
                $response['data'] = $config;
            }
        } catch (Exception $e) {
            $response['errors'][] = $e->getMessage();
            throw $e;
        }

        $this->set(compact('response'));
        $this->set('_serialize', 'response');
    }
208509
private function setHost(array $config)
    {
        if (!isset($config[self::CONFIG_HOST]) || trim($config[self::CONFIG_HOST]) === "") {
            throw new Exception("Invalid config - host missing.");
        }

        $this->host = trim($config[self::CONFIG_HOST]);
    }
1215289
public function deleteEvent($eventId)
    {
        if (is_null($eventId) || $eventId == '') {
            throw new Exception('The eventId is required to delete an event.');
        }

        $params = array(
            'method' => 'sp.event.delete',
            'event_id' => $eventId
        );

        return $this->_makeApiRequest($params);
    }
1092337
private function _throwDispatchException( $message, $exception_code = 0 )
    {
        $exception = new \Exception( $message, $exception_code );

		if ( is_object($this->_events_manager) )
        {
            /**
             * If the event returns false -> exit and don't throw exception
             */
            if ( $this->_events_manager->fire( "dispatch:beforeException", $this, array("exception" => $exception) ) == false )
            {
                return false;
            }
		}

        throw $exception;
    }
297358
public function setConfiguration(array $configuration): void
    {
        if ($this->frozen) {
            throw new Exception('The application configuration is already defined');
        }
        $this->configuration = $this->createApplicationConfiguration($configuration);
        $this->frozen = true;
    }
1013204
protected function setup(array $config = [])
    {
        if (!isset($config['data_provider'])) {
            throw new Exception(translate('{data_provider} must be a DatapPovider objetc'), 500, Exception::BADARGUMENTS);
        } elseif (isset($config['data_provider']) && !($config['data_provider'] instanceof DataProviderInterface)) {
            throw new Exception(translate('{data_provider} must be a DatapPovider objetc'), 500, Exception::BADARGUMENTS);
        }

        if (!isset($config['columns'])) {
            throw new Exception(translate('{columns} must be an array type Column[]'), 500, Exception::BADARGUMENTS);
        }

        parent::setup($config);

        $this->setupColumns();
    }
334106
public function onException(GetResponseForExceptionEvent $event)
    {
        if (!$this->eventRequestMatches($event)) {
            return;
        }
        $event->setResponse($this->responseTransformer->createResponseFromContent($event->getException()));
    }
45173
public static function errorLog(string $message, \Exception $exception)
    {
        $logger = Config::getLogger();
        if ($logger) {
            $logger->error($message, ['exception' => $exception]);
        }
    }
1244769
public function onCoreException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        $request = $event->getRequest();

        if ($request->isXmlHttpRequest()) {
            if ($exception instanceof AuthenticationException || $exception instanceof AccessDeniedException) {
                $event->setResponse(new Response('', 403));
            }
        }
    }
340047
protected function _throwException($exception = null)
    {
        if ($exception !== null) {
            if (!Configure::read('debug') && $exception instanceof SecurityException) {
                $exception->setReason($exception->getMessage());
                $exception->setMessage(self::DEFAULT_EXCEPTION_MESSAGE);
            }
            throw $exception;
        }
        throw new BadRequestException(self::DEFAULT_EXCEPTION_MESSAGE);
    }
21371
public function on($event, $callback)
        {
            if (!is_callable($callback)) {
                throw new Exception('Socketio::on() type callback must be callable.');
            }

            if (!isset($this->callbacks[$event])) {
                $this->callbacks[$event] = array();
            }

            // @TODO Handle case where callback is a string
            if (in_array($callback, $this->callbacks[$event])) {
                $this->stdout('debug', 'Skip existing callback');
                return;
            }

            $this->callbacks[$event][] = $callback;
        }
600680
protected function triggerError ($errorMessage)
	{
		$this->hasError 	= true;
		$this->errorMessage	= $errorMessage;
		
		throw new Exception ($errorMessage);
	}