Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExceptionMessageFactory.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  private $messageFactory;
17 
21  public function __construct(Factory $messageFactory)
22  {
23  $this->messageFactory = $messageFactory;
24  }
25 
29  public function createMessage(\Exception $exception, $type = MessageInterface::TYPE_ERROR)
30  {
31  if ($exception instanceof \Exception) {
32  return $this->messageFactory->create($type)
33  ->setText($exception->getMessage());
34  }
35  throw new RuntimeException(
36  new \Magento\Framework\Phrase("Exception instance doesn't match %1 type", [\Exception::class])
37  );
38  }
39 }
$type
Definition: item.phtml:13
createMessage(\Exception $exception, $type=MessageInterface::TYPE_ERROR)
$messageFactory
Definition: messages.php:10