
Exception::getTrace() 메소드는 현재 예외가 발생한 호출 스택을 배열로 반환합니다.
예를 들어, 다음 코드를 실행했을 때, 호출 스택을 가져올 수 있습니다.
#hostingforum.kr
php
try {
$a = 1 / 0;
} catch (Exception $e) {
$trace = $e->getTrace();
var_dump($trace);
}
getTrace() 메소드는 현재 예외가 발생한 호출 스택을 다음과 같이 배열로 반환합니다.
```php
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected]=>
string(12) "Division by zero"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "example.php"
["line":protected]=>
int(5)
["trace":"Exception":private]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(5)
["function"]=>
string(3) "try"
["args"]=>
array(0) {
}
["class"]=>
string(0) ""
["object"]=>
string(0) ""
}
[1]=>
array(6) {
["file"]=>
string(9) "example.php"
["line"]=>
int(10)
["function"]=>
string(5) "catch"
["args"]=>
array(1) {
[0]=>
object(Exception)#2 (7) {
["message":protected
2025-04-23 01:07