Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Handle Specific Exception Types | Understanding PHP Errors and Basic Exception Handling
PHP Error Handling and Exceptions
Sektion 1. Kapitel 6
single

single

bookChallenge: 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 InvalidArgumentException if the argument is not an integer.
  • Throw a RuntimeException if the argument is a negative integer.
  • Return the argument multiplied by 2 for valid input.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 6
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt