Avsnitt 1. Kapitel 6
single
Challenge: Handle Specific Exception Types
Svep för att visa menyn
Uppgift
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.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 6
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal