Create the service factory
Catch any exceptions that might occur

@return null|ServiceResponse
962723
public function createServiceFactory()
    {
        $factory = ServiceFactory::create();
        $service = $factory->getService($this->payment, ServiceFactory::INTENT_PAYMENT);

        try {
            $serviceResponse = $service->initiate($this->getGatewayData());
        } catch (Exception $ex) {
            // error out when an exception occurs
            user_error($ex->getMessage(), E_USER_WARNING);
            return null;
        }

        return $serviceResponse;
    }
1302867
public function getService()
    {
        if (!$this->service) {
            /** @var \OAuth\ServiceFactory $serviceFactory */
            $serviceFactory = $this->app->make('oauth/factory/service');
            $this->service = $this->factory->createService($serviceFactory);
        }

        return $this->service;
    }
631155
public function create(CreateServiceRequest $serviceRequest)
    {
        $response = $this->httpClient->post(
            'service/',
            [
                'body' => json_encode($serviceRequest->toArray())
            ]
        );

        return ServiceResponse::createFromHttpResponse($response);
    }
530176
public static function create()
	{
		switch (func_num_args()) {
			case 0:
				return new ServiceOptions();
			case 1:
				return new ServiceOptions(func_get_arg(0));
			case 2:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1));
			case 3:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1), func_get_arg(2));
			case 4:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3));
			case 5:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
			case 6:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5));
			case 7:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5), func_get_arg(6));
			case 8:
				return new ServiceOptions(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5), func_get_arg(6), func_get_arg(7));
			default:
				throw new \InvalidArgumentException('More than 8 arguments supplied, please be reasonable.');
		}
	}
1250964
protected function modelFactory()
    {
        if ($this->modelFactory === null) {
            throw new Exception(sprintf(
                'Model Factory is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->modelFactory;
    }
253048
private static function createDriver()
    {
        if (self::$factory === null) {
            throw new \Exception("No loop driver factory set; Either pass a driver to Loop::execute or set a factory.");
        }

        $driver = self::$factory->create();

        if (!$driver instanceof Driver) {
            $type = is_object($driver) ? "an instance of " . get_class($driver) : gettype($driver);
            throw new \Exception("Loop driver factory returned {$type}, but must return an instance of Driver.");
        }

        return $driver;
    }
822171
protected function createResponseBuilder()
	{
		try
		{
			$body = $this->streamFactory->createStream(fopen('php://temp', 'w+'));
		}
		catch (\InvalidArgumentException $e)
		{
			throw new \RuntimeException('Can not create "php://temp" stream.');
		}

		$response = $this->messageFactory->createResponse(200, null, [], $body);

		return new ResponseBuilder($response);
	}
1149351
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var array  $config */
        $config            = $serviceLocator->get('Config');
        $displayExceptions = array_key_exists('view_manager', $config)
            && array_key_exists('display_exceptions', $config['view_manager'])
            && $config['view_manager']['display_exceptions'];

        $listener = new SendApiProblemResponseListener();
        $listener->setDisplayExceptions($displayExceptions);

        if ($serviceLocator->has('Response')) {
            $response = $serviceLocator->get('Response');
            if ($response instanceof HttpResponse) {
                $listener->setApplicationResponse($response);
            }
        }

        if ($serviceLocator->has('Application')) {
            /** @var Application $app */
            $app = $serviceLocator->get('Application');
            $mvcEvent = $app->getMvcEvent();

            if ($mvcEvent instanceof MvcEvent) {
                $listener->setMvcEvent($mvcEvent);
            }
        }



        return $listener;
    }
331142
private function createHealthService()
    {
        $resourceChecker = call_user_func($this->resourceCheckerClosure);

        $cache = call_user_func($this->cacheClosure);

        $this->healthServiceClosure = function () use (
            $resourceChecker,
            $cache
        ) {
            return $this->instantiateService($resourceChecker, $cache);
        };

        $this->healthService = call_user_func($this->healthServiceClosure);
    }
206222
private function createServiceProvider()
    {
        $serviceProviderClass = $this->moduleName . "ServiceProvider";
        $serviceProviderFileName = $serviceProviderClass . '.php';
        $serviceProviderPath = $this->moduleDirectory . DIRECTORY_SEPARATOR . $serviceProviderFileName;

        if (file_exists($serviceProviderPath) && $this->isForce == false) {
            $this->info($serviceProviderFileName . ' file exists. Skip.');
            return $serviceProviderPath;
        }

        $serviceProviderContent = $this->generateServiceProviderContent();
        file_put_contents($serviceProviderPath, $serviceProviderContent);
        $this->info('ServiceProvider file is set: ' . $serviceProviderFileName);
        $this->line($serviceProviderPath);

        return $serviceProviderPath;
    }
1173057
public function createErrorHandler()
    {
        $config = $this->getConfig();
        if (!isset($config['error_handler'])) {
            throw new Exception\RuntimeException('Not found error handler config');
        }
        
        $errorHandlerConfig = $config['error_handler']->toArray();
        $adapter = !isset($errorHandlerConfig['adapter']) ? HandlerDefault::class : $errorHandlerConfig['adapter'];
        $this->setServiceFactories('errorHandler', $adapter, false);
    }
973839
public function create()
    {
        foreach ($this->driverClasses as $driverClass) {
            try {
                $driver = new $driverClass();

                return $driver;
            } catch (\Exception $e) {
            }
        }

        return null;
    }
609489
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $frontController = FrontController::getInstance();

        // handle injections
        $frontController->setDispatcher($serviceLocator->get('Dispatcher'));
        $frontController->setRequest($serviceLocator->get('Request'));
        $frontController->setResponse($serviceLocator->get('Response'));
        $frontController->setRouter($serviceLocator->get('Router'));

        // get config
        $appConfig = $serviceLocator->get('Config');
        if (isset($appConfig['front_controller'])) {
            $config = ArrayUtils::merge($this->defaultOptions, $appConfig['front_controller']);
        } else {
            $config = $this->defaultOptions;
        }

        // handle configuration
        $frontController->setModuleControllerDirectoryName($config['module_controller_directory_name']);
        $frontController->setBaseUrl($config['base_url']);
        $frontController->setControllerDirectory($config['controller_directory']);
        $frontController->throwExceptions($config['throw_exceptions']);
        $frontController->returnResponse($config['return_response']);
        $frontController->setDefaultModule($config['default_module']);
        $frontController->setDefaultAction($config['default_action']);
        $frontController->setDefaultControllerName($config['default_controller_name']);
        $frontController->setParams($config['params']);
        foreach ($config['plugins'] as $plugin) {
            if (is_array(($plugin))) {
                $pluginClass = $plugin['class'];
                $stackIndex = $plugin['stack_index'];
            } else {
                $pluginClass = $plugin;
                $stackIndex = null;
            }
            // plugins can be loaded with service locator
            if ($serviceLocator->has($pluginClass)) {
                $plugin = $serviceLocator->get($pluginClass);
            } else {
                $plugin = new $pluginClass();
            }
            $frontController->registerPlugin($plugin, $stackIndex);
        }

        // set action helper plugin manager
        $actionHelperManager = $serviceLocator->get('ActionHelperManager');
        ActionHelperBroker::setPluginLoader($actionHelperManager);
        ActionHelperBroker::addHelper($actionHelperManager->get('viewRenderer'));

        // start layout, if needed
        if (isset($appConfig['layout'])) {
            Layout::startMvc($appConfig['layout']);
        }

        return $frontController;
    }
451012
public function build(): GetResponseBodyForInterceptionRequest
	{
		$instance = new GetResponseBodyForInterceptionRequest();
		if ($this->interceptionId === null) {
			throw new BuilderException('Property [interceptionId] is required.');
		}
		$instance->interceptionId = $this->interceptionId;
		return $instance;
	}
1172362
function newService()
    {
        $callable = $this->callable;
        if ($callable === null)
            ## no callable provided but rather not throw exception
            throw new \Exception('No Factory Callable Provided.');
        
        // ..
        // DO_LEAST_PHPVER_SUPPORT 5.4 Closure Bind
        if ($callable instanceof \Closure && version_compare(phpversion(), '5.4.0') > 0)
            $callable = $callable->bindTo($this);

        return call_user_func( $callable, $this->services() );
    }
1257144
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        $controllerLoader = $serviceLocator->get('ControllerLoader');

        /** @var $systemConfig ProcessingConfig */
        $systemConfig = $serviceLocator->get('prooph.link.system_config');

        if ($serviceLocator->has('prooph.link.dashboard.widget_blacklist')) {
            $blacklist = $serviceLocator->get('prooph.link.dashboard.widget_blacklist');

            if (! $blacklist instanceof WidgetBlacklist) {
                throw new \RuntimeException("Widget blacklist should implement " . WidgetBlacklist::class
                . ". Got " . (is_object($blacklist))? get_class($blacklist) : gettype($blacklist));
            }
        }

        $controllers = [];

        $sortArr = [];

        if ($systemConfig->isConfigured()) {

            foreach ($config['prooph.link.dashboard'] as $widgetName => $widgetConfig) {

                if (isset($blacklist)) {
                    if ($blacklist->isWidgetOnList($widgetName)) {
                        continue;
                    }
                }

                if (! array_key_exists('controller', $widgetConfig)) {
                    throw new \RuntimeException('controller key missing in widget config: ' . $widgetName);
                }

                $sortArr[$widgetName] = (isset($widgetConfig['order']))? (int)$widgetConfig['order'] : 0;
            }

            asort($sortArr);

        } else {
            $sortArr['system_config_widget'] = 1;
        }

        foreach ($sortArr as $widgetName => $order) {
            $controller = $controllerLoader->get($config['prooph.link.dashboard'][$widgetName]['controller']);

            $controller->setWidgetConfig(new WidgetConfig($config['prooph.link.dashboard'][$widgetName]));

            $controllers[] = $controller;
        }

        return new DashboardProvider($controllers);
    }
1245580
private function getRequestFactory()
    {
        if ($requestFactory = $this->app->config->get('swap.request_factory')) {
            return $this->app[$requestFactory];
        }

        return null;
    }