V
V
Vladislav2020-11-03 12:15:38
Design
Vladislav, 2020-11-03 12:15:38

Exception or Throwable?

Here is an example code:

try {
                $this->startAnyMethod();
            } catch (\Exception $e) {
                $this->savelog($e);
            } catch (\Throwable $e) {
               $this->savelog($e);
        }


When hovering over the $e variable in the second catch, the storm shows $e Exception | Throwable
And when you direct on the first $e that only Exception there.

Related to this is the question. Is it right to do this, two caches, or is it better to leave only one Throwable, since it also catches Exception.

Why do I need two, the point is that there are such errors that Exception does not catch, but Throwable does.
And I think that by specifying one cache and specifying Throwable there, it will be the same as the code above with only one branch.
Am I right or not? (I don’t have the opportunity to check my theory, because I don’t know what errors the exception does NOT catch)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Александр Тарасов, 2016-06-08
@VoxelGod

это называется Pattern Overlay, по-русски наложение шаблона. Шаблон это как раз "точки". Этот плагин https://vegas.jaysalvat.com/ умеет такой эффект накладывать

I
Ilya, 2020-11-03
@cr1gger

Your design is meaningless. Exception implements Throwable. those. If you catch Throwable, then Exception will be caught anyway.

try {
  $this->startAnyMethod();
} catch (\Throwable $e) {
  $this->savelog($e);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question