Sektion 1. Kapitel 6
single
Challenge: Handle Specific Exception Types
Stryg for at vise menuen
Opgave
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 alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 6
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat