Throwing simple exceptions are a common practice, so I would think it would be 'built-into' Symfony2, 'right out of the box". However, executing the following code, I get the error partly shown in this question's title and fully shown below.
if( ( $result === FALSE ) || ( $result !== 1 ) ) {
throw new Exception( 'update user account data function -- ' .
'update return value: ' . $result . ' - ' .
'unable to update your account!' );
} // if( ( $result === FALSE ) || ( $result !== 1 ) ) ...
This error tells me that the new Exception class isn't supported by Symfony2 unless I also add it to my Controller's use area, but I don't know the value to add there to use this feature of PHP.
Would someone please tell me what to put in my use area?
In my code, based on the examples shown in the w3School's PHP Exception page at https://www.w3schools.com/php/php_exception.asp, the $result variable is set by the Doctrine DBAL update method (http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html#update), which returns the number of rows updated or FALSE if there was an error.
I know that the update method in my code works because most of the time $result is assigned a non-zero return value and no exceptions occur, but sometimes $result is assigned a 0, still no exception, indicating that a row that is known to exist isn't actually being updated.
Is there some way to get why the update failed?
In this situation, I try to throw an exception using the above code, but then Symfony2 displays the following:
Attempted to load class "Exception" from namespace "AppBundle\Controller". Did you forget a "use" statement for e.g. "Symfony\Component\Security\Acl\Exception\Exception", "Symfony\Component\Serializer\Exception\Exception" or "Symfony\Component\Config\Definition\Exception\Exception"? 500 Internal Server Error - ClassNotFoundException
- in src/AppBundle/Controller/BreakinOutAdminController.php at line 1361
1358.
1359. if( ( $result === FALSE ) || ( $result !== self::ONE_ROW ) ) {
1360.
1361. throw new Exception( 'update user account data function -- ' .
1362. 'update return value: ' . $result . ' - ' .
1363. 'unable to update your account!' );
1364.
Line 1361 is highlighted in the page Symphony2 didplays.
So, two question:
What should I put in my use area so I can throw an exception with my own message?
Is there some way to get why the update failed?
Thank you.