R
R
Roman2018-03-21 17:49:48
PHP
Roman, 2018-03-21 17:49:48

Why is catching the exception not working?

Good day.
Made this code:

<?php
function foo(
      string $m): void{
  if(!is_string($m)){
    throw new Exception('не строка');
  }
}
try{
  foo(15);
}
catch(Exception $e){
  echo 'перехваченное исключение', $e->getMessage();
}

I have a blank page in the browser, why?
And another question: is it possible to catch all types of exceptions at once using Throwable? Or are there other ways (without listing all types)?
Thanks for the replies.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question