SectionΒ 1. ChapterΒ 6
single
Challenge: Handle Specific Exception Types
Swipe to show menu
Task
Swipe to start coding
Practice using multiple catch blocks to handle specific exception types in PHP. Build on your understanding of built-in exception classes by writing a function that throws different exceptions based on input.
- Throw an
InvalidArgumentExceptionif the argument is not an integer. - Throw a
RuntimeExceptionif the argument is a negative integer. - Return the argument multiplied by 2 for valid input.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 6
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat