Example 1 — Show the Throw Line
Throw an Exception and print the line number from getLine().
<?php
try {
throw new Exception("Invalid amount");
} catch (Exception $e) {
echo "Thrown on line ", $e->getLine(), PHP_EOL;
} How It Works
- The throw statement creates the Exception.
- PHP stores the current line number on the object.
- getLine() returns that integer.
- The catch block only reads the value; it does not change it.

