Challenge 1 — Solution Task: Write a function squareRoot($n) that throws an Exception if $n is negative (square roots of negative numbers aren't real numbers), otherwise returns sqrt($n). Call it inside a try/catch with both a valid and an invalid value, echoing either the result or the caught error message. "; echo squareRoot(-4) . "
"; // this line throws } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ?> Output: 4 Error: Cannot take the square root of a negative number: -4 Notes: - squareRoot(16) succeeds and echoes normally, since 16 is non-negative - execution continues into the try block's second line. - squareRoot(-4) throws before it ever returns a value, immediately jumping to the catch block - the "echo squareRoot(-4)" line's own echo never actually completes, since the exception interrupts it. - Only one message from the try block ever reaches the catch block, even though there could in principle have been multiple calls that might throw - the very first exception thrown stops the rest of the try block from running at all.