PHP Try-Catch (Not a 'Uyarı') yakalamak için başarısız

2 Cevap php

Ben neden ve iki istisna yakalamak gereken bazı PHP kodu var:

try{
    @$this->connector->connect(); // Suppress the default warning (doesn't effect 'throw')
} catch(BadArgumentException $e) {} // Works, no error, following code executes.

try{
    @$this->connector->connect(array('user' => 'Doesn\'t exist', 'pass' => 'invalid'));
} catch(AuthenticationException $e) {} // DOESN'T WORK - Passed to the exception handler.

echo 'Not executed!'; // This isn't executed.

I catch(Exception $e) bunları genelleştirerek çalıştı ama ... hiçbir fikri neden aynı sorun olsun var.

Herhangi bir yardım?

2 Cevap

Tamam ben bir namespacing sorun olduğunu öğrendim: (Bu durumda use Framework\AuthenticationException denemek ve use, bir var olmayan alanlı elemanı zaman gerçekten ben {gerektiğinde PHP şikayetçi değil gibi görünüyor [(2)]}). Herşey şeftali şimdi :)

Şerefe

Ayrıca @ kullanarak PHP son derece yavaş olduğunu bilmeli. , Üretim kodunda kullanmak etmeyiniz lütfen.