Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Exception Class Reference
Inheritance diagram for Exception:
InputException AbstractAggregateException LocalizedException AggregateExceptionInterface

Public Member Functions

 __construct (Phrase $phrase=null, \Exception $cause=null, array $messages=[], $code=0)
 
 addMessage (AbstractMessage $message)
 
 getMessages ($type='')
 
- Public Member Functions inherited from InputException
 __construct (Phrase $phrase=null, \Exception $cause=null, $code=0)
 
- Public Member Functions inherited from AbstractAggregateException
 __construct (Phrase $phrase, \Exception $cause=null, $code=0)
 
 addError (Phrase $phrase)
 
 addException (LocalizedException $exception)
 
 wasErrorAdded ()
 
 getErrors ()
 
- Public Member Functions inherited from LocalizedException
 __construct (Phrase $phrase, \Exception $cause=null, $code=0)
 
 getRawMessage ()
 
 getParameters ()
 
 getLogMessage ()
 

Protected Attributes

 $messages = []
 
- Protected Attributes inherited from AbstractAggregateException
 $errors = []
 
 $originalPhrase
 
- Protected Attributes inherited from LocalizedException
 $phrase
 
 $logMessage
 

Additional Inherited Members

- Static Public Member Functions inherited from InputException
static invalidFieldValue ($fieldName, $fieldValue, \Exception $cause=null)
 
static requiredField ($fieldName)
 
- Data Fields inherited from InputException
const DEFAULT_MESSAGE = 'One or more input exceptions have occurred.'
 
const INVALID_FIELD_RANGE = 'The %fieldName value of "%value" must be between %minValue and %maxValue'
 
const INVALID_FIELD_MIN_VALUE = 'The %fieldName value of "%value" must be greater than or equal to %minValue.'
 
const INVALID_FIELD_MAX_VALUE = 'The %fieldName value of "%value" must be less than or equal to %maxValue.'
 
const INVALID_FIELD_VALUE = 'Invalid value of "%value" provided for the %fieldName field.'
 
const REQUIRED_FIELD = '"%fieldName" is required. Enter and try again.'
 

Detailed Description

Exception to be thrown when data validation fails

@api

Since
100.0.2

Definition at line 21 of file Exception.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Phrase  $phrase = null,
\Exception  $cause = null,
array  $messages = [],
  $code = 0 
)

Constructor

Parameters
\Magento\Framework\Phrase$phrase
\Exception$cause
array$messagesValidation error messages
int$code

Definition at line 36 of file Exception.php.

41  {
42  if (!empty($messages)) {
43  $message = '';
44  foreach ($messages as $propertyMessages) {
45  foreach ($propertyMessages as $propertyMessage) {
46  if ($message) {
47  $message .= PHP_EOL;
48  }
49  $message .= $propertyMessage;
50  $this->addMessage(new Error($propertyMessage));
51  }
52  }
53  $phrase = new Phrase($message);
54  }
55  parent::__construct($phrase, $cause, $code);
56  }
addMessage(AbstractMessage $message)
Definition: Exception.php:64
$message
$code
Definition: info.phtml:12

Member Function Documentation

◆ addMessage()

addMessage ( AbstractMessage  $message)

Setter for message

Parameters
\Magento\Framework\Message\AbstractMessage$message
Returns
$this

Definition at line 64 of file Exception.php.

65  {
66  if (!isset($this->messages[$message->getType()])) {
67  $this->messages[$message->getType()] = [];
68  }
69  $this->messages[$message->getType()][] = $message;
70  return $this;
71  }
$message

◆ getMessages()

getMessages (   $type = '')

Getter for messages by type or all

Parameters
string$type
Returns
array

Definition at line 79 of file Exception.php.

80  {
81  if ('' == $type) {
82  $allMessages = [];
83  foreach ($this->messages as $messages) {
84  $allMessages = array_merge($allMessages, $messages);
85  }
86  return $allMessages;
87  }
88  return $this->messages[$type] ?? [];
89  }
$type
Definition: item.phtml:13

Field Documentation

◆ $messages

$messages = []
protected

Definition at line 26 of file Exception.php.


The documentation for this class was generated from the following file: