C # vs PHP istisna Taşıma

0 Cevap

Bu gerçekten temel soru (umarım) 'dir. Ben yaptım istisna işleme çoğu c # ile olmuştur. C # bir try catch bloğu içinde hatalar dışarı catch kod tarafından ele herhangi bir kod. Örneğin

try
{
 int divByZero=45/0;
}
catch(Exception ex)
{
 errorCode.text=ex.message();
}

Hata errorCode.text olarak gösterilecektir. Ben denemek ve ancak php aynı kodu çalıştırırsanız:

try{
    $divByZero=45/0;
    }
catch(Exception ex)
{
  echo ex->getMessage();
}

The catch code is not run. Based on my limeted understanding, php needs a throw. Doesn't that defeat the entire purpose of error checking? Doesn't this reduce a try catch to an if then statement? if(dividing by zero)throw error Please tell me that I don't have to anticipate every possible error in a try catch with a throw. If I do, is there anyway to make php's error handling behave more like c#?

0 Cevap