Home » PHP » Metode getPrevious() PHP

Metode getPrevious() PHP

by Hanifah Nurbaeti
by Hanifah Nurbaeti

Contoh
Dapatkan informasi tentang exception sebelumnya:

<?php
try {
  try {
    throw new Exception("An error occurred", 1);
  } catch(Exception $e1) {
    throw new Exception("Another error occurred", 2, $e1);
  }

} catch (Exception $e2) {
  echo $previous = $e2->getPrevious();
  echo $previous->getMessage();
}
?>
  /* Output : 
Exception: An error occurred in /home/TwT0ln/prog.php:4
Stack trace:
#0 {main}An error occurred

Definisi dan Penggunaan

Jika exception dipicu oleh exception yang lain, maka metode getPrevious() bisa digunakan untuk mengembalikan exception lainnya. Jika tidak,maka akan mengembalikan null.

Syntax

$exception->getPrevious()

Detail Teknis

Nilai Kembalian :Mengembalikan nilai integer

You may also like