horst
horst

Reputation: 23

DoctrineORMModule and Zend Framework 2 - No exceptions thrown

I use the DoctrineORMModule (https://github.com/doctrine/DoctrineORMModule, installed via Composer) and ZF2 to develop a web application.

My problem is, that I dont get exceptions from doctrine, only an "Internal 500" Error. Even with

ini_set('display_errors', 1); 
error_reporting(E_ALL);

I dont see an error, just the "Internal 500" Message (I applied those settigns in php.ini too). There are no entries in "php_error_log" too.

If I surround the lines with a try-catch-block, no exception is caught. This happens while calling flush() and persist(). Other PHP-Errors are displayed.

Example:

ini_set('display_errors', 1);
error_reporting(E_ALL);

$rel  = new \MyApp\Entity\UserRelationship();
$rel->relatingUser = $user;
$rel->relatedUser  = $friend;

try {
    $em->persist($rel);
} catch ( Exception $e ) {
    var_dump($e);
}

This results in an "Internal 500" Error, but I guess doctrine should throw an error.

I googled around for hours, but I cant figure out, if this is the default behaviour, or if you have to configure doctrineORMModule to log/throw exceptions. I would be very thankful if someone could give me a hint on how to get exceptions, because this slows me down very hard.

Edit: I can use persist() and flush(), the database-queries are executed, everything is alright. Its just if I make mistakes in the entities and want to persist or flush them, I dont get exceptions. The "Internal 500" is not shown, if I echo something before persist(), but the database is not updated or anything.

Edit2: The error in the example above, was a wrong "mappedBy"-entry and/or a wrong named setter. Still no exceptions :)

Upvotes: 2

Views: 786

Answers (1)

Jurian Sluiman
Jurian Sluiman

Reputation: 13558

This is not really Doctrine related. The exceptions can be thrown in any library you are using. You must know that in general when you do not catch exceptions, php will create a fatal error because of the uncaught exception. I think you made a mistake when you set the display_errors / error_reporting() because that should show the php error.

Furthermore, Zend Framework has an exception handler to catch exceptions within the run part. If you had this code within an action controller of Zend\Mvc you would be shown a nice error page. The framework catches errors in a lot of places, but if you put this code without any catch it wouldn't get caught.

Upvotes: 1

Related Questions