Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Why Exception is not instance of Throwable?

I think in all programming languages Exception class is instance of Throwable interface.

Take a look at following code which shows Exception is not instance of Throwable in php.

try {

    throw new InvalidArgumentException("error message");

} catch (InvalidArgumentException $e) {

    if ($e instanceof Exception) {
        echo '$e is exception';             // this line gets executed
    }

    if ($e instanceof Throwable) {
        echo '$e is throwable';             // but this one never
    }

}

It makes problem with chaining exceptions where Exception class constructor accepts Throwable in it's last argument.

php version: 5.6.23

Any solution?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Throwable is the base interface for any object that can be thrown via a throw statement in PHP 7, including Error and Exception. And your code produces: $e is exception $e is throwable if you have PHP version >= 7

But you have PHP version 5.6.23, so Throwable interface is not available for this version.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!