Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
It all depends on whether both classes together are part of the same layer or if it is an interaction between different layers.
In the first case, exceptions can be combined with a single interface (or parent exception). And on this generalized exception to be tied in another layer.
class FirstException extend ModuleException {}
class SecondException extend ModuleException {}
class ModuleFirst
{
public function work()
{
throw new FirstException('first);
}
}
class ModuleSecond
{
public function work()
{
throw new SecondException('second);
}
}
try {
$module->work();
} catch(ModuleException $e) {
// обработка
}
class FirstException {}
class SecondException {}
class ModuleFirst
{
public function work()
{
try {
$module2->work();
} catch(SecondException $e) {
throw new FirstException($e->getMessage, 0, $e);
}
}
}
class ModuleSecond
{
public function work()
{
throw new SecondException('second);
}
}
try {
$module1->work();
} catch(FirstException $e) {
// обработка
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question