rakete rakete - 5 years ago 219
PHP Question

Symfony2 (debug mode) catching vendor exception before I can

I am using the Klarna SDK to implement their payment methods. The SDK calls the api and checks the response code. If the response-code is not 0 (all codes > 0 are errors) an exception is thrown. In my controller I try to catch the exception to handle it. But in the development enviroment the "exception detected" comes first.

vendor/.../klarna/.../function.php

public function xy() {
$status = $this->getResponse();
if($status > 0) throw new KlarnaException(...);
}


src/AppBundle/Controller/MyController

public function indexAction() {
$k = new Klarna();
try {
$k->xy();
} catch(Exception $e) {
die('Something wrent wrong');
}
}


But the catch() is never executed because the execution stopps when detecting the exception in the vendor. How to prevent debuggin vendor classes?

Answer Source

Symfony loves namespaces, so if you use any native PHP classes you need to add them using a use statement.
So in your case if you want the Exception class, use \Exception;
If you where using a DateTime object, use \DateTime;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download