php8.5
Home/ Manual/ yaf / yaf_exception/ Yaf_Exception::getPrevious

Yaf_Exception::getPrevious

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve the previous exception

Description

Yaf_Exception::getPrevious(): Throwable

This method is inherited from the base Throwable hierarchy and returns the exception that was chained as the previous one, if any.

Parameters Parameters

Return Values

Returns the previous Throwable if available, null otherwise.

Examples

Yaf_Exception::getPrevious example

php
<?php
try {
    $previous = new RuntimeException("Failed to open view script", 1024);
    throw new Yaf_Exception(
        "Failed to dispatch the request",
        YAF_ERR_DISPATCH_FAILED,
        $previous
    );
} catch (Yaf_Exception $e) {
    var_dump($e->getCode());
    $prev = $e->getPrevious();
    var_dump(get_class($prev));
    var_dump($prev->getMessage());
    var_dump($prev->getCode());
}
?>

The above example will output something similar to:

output
int(514)
string(16) "RuntimeException"
string(26) "Failed to open view script"
int(1024)

See Also

  • Yaf_Exception::__construct
  • Yaf_Exception

Source: reference/yaf/yaf_exception/getprevious.xml · from the official PHP manual (php/doc-en)