newrelic_notice_error(string $message[, exception $exception])
Report an error at this line of code and collect a complete stack trace.


Agent version 2.6 or higher.


Report an error at the line of code where the method is called, with a complete stack trace. Include this method as part of an error handler. When there are multiple calls to this method in a single transaction, the agent only retains the exception from the last call.


Parameter Description



Required. Provide a meaningful error message for use in error traces.



Optional. Defaults to null.

If you pass an exception, you must pass a valid PHP Exception class. The agent captures the stack frame from that class, rather than the stack at the time this function was called.

If null or omitted, the agent reports an "exception" in the same format created by Exception::__toString.

Return value(s)

Returns null regardless of result.


Report error messages with line numbers

// Error handler function
function example_handler($errno, $errstr) {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_notice_error($errno . $errstr, null);

// Set error handler

Report error message and exception

// Exception handler function
function example_handler (Exception $ex)
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_notice_error($ex->getMessage(), $ex);
    throw $ex;

// Set exception handler