Каковы наилучшие методы перехвата и повторного создания исключений? ⇐ Php
-
Anonymous
Каковы наилучшие методы перехвата и повторного создания исключений?
Should caught exceptions be re-thrown directly, or should they be wrapped around a new exception?
That is, should I do this:
try { $connect = new CONNECT($db, $user, $password, $driver, $host); } catch (Exception $e) { throw $e; } or this:
try { $connect = new CONNECT($db, $user, $password, $driver, $host); } catch (Exception $e) { throw new Exception("Exception Message", 1, $e); } If your answer is to throw directly please suggest the use of exception chaining, I am not able to understand a real world scenario where we use exception chaining.
Источник: https://stackoverflow.com/questions/555 ... exceptions
Should caught exceptions be re-thrown directly, or should they be wrapped around a new exception?
That is, should I do this:
try { $connect = new CONNECT($db, $user, $password, $driver, $host); } catch (Exception $e) { throw $e; } or this:
try { $connect = new CONNECT($db, $user, $password, $driver, $host); } catch (Exception $e) { throw new Exception("Exception Message", 1, $e); } If your answer is to throw directly please suggest the use of exception chaining, I am not able to understand a real world scenario where we use exception chaining.
Источник: https://stackoverflow.com/questions/555 ... exceptions
Мобильная версия