PHP theorytheory 0/50 · 0%
Fundamentals · easy

18. Exceptions

Handling errors gracefully.

PHP uses try/catch/finally blocks with the throw keyword to signal exceptional conditions using objects that implement Throwable, such as Exception or Error. Multiple catch blocks can handle different exception types.

The finally block always runs, making it suitable for cleanup like closing file handles regardless of whether an exception occurred.

Check your understanding

  1. 1. Which keyword raises an exception?

  2. 2. Which block always executes regardless of exceptions?