PHP throw exception to parent/calling code

How can I throw an exception at the the caller of a function instead of inside the called function. For example:

function a() {
  //code that throws 'Exception'
}

a(); <-- error should occur here as "Uncaught 'Exception'";

In java, you can:

function a() throws Execption {
  //code that throws exception
}

a(); <-- error will occur here instead of inside the function.

so that instead of having to have the try/catch in function a you “pass” the exception to where the function was called from.

I’m guessing it must be possible because the php mysqli function ‘mysqli_stmt::execute’ does this (https://www.php.net/manual/en/mysqli-stmt.execute.php).

The reason I’m trying to do this is I’m writing a php library file and I want the error to appear in my index.php file, not in the library.php file where the function is that I’ve called. For example:

index.php

include("library.php");
a();

library.php

function a() {
//code that throws error
}