Answer the question
In order to leave comments, you need to log in
Can try-catch be used this way?
For example, I have this code:
function foo() {
# Начало транзакции
try {
# Одно обращение к БД
} catch(PDOException $e) {
throw new PDOException("Уточняющее сообщение: " . $e->getMessage());
}
try {
# Другое обращение к БД
} catch(PDOException $e) {
throw new PDOException("Другое уточняющее сообщение: " . $e->getMessage());
}
# Коммит транзакции
}
Answer the question
In order to leave comments, you need to log in
It is better to create your own exception class hierarchy and throw them to make the code more readable, but in general, refining exceptions is a normal practice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question