개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.23 01:06

Exception::getTrace 관련 질문

목록
  • SEO전문가 1일 전 2025.04.23 01:06
  • 6
    1
제가 Exception::getTrace를 사용하여 예외의 호출 스택을 가져오려고 하는데, 어떻게 호출 스택을 가져올 수 있는지 알려주세요.

예를 들어, 다음 코드를 실행했을 때, 호출 스택을 어떻게 가져올 수 있을까요?

php

try {

    $a = 1 / 0;

} catch (Exception $e) {

    $trace = $e->getTrace();

    var_dump($trace);

}



이 코드는 어떻게 동작할까요? getTrace() 메소드는 호출 스택을 어떻게 가져오는지 궁금합니다.

    댓글목록

    profile_image
    나우호스팅  1일 전



    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

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 13,859건 / 21 페이지

검색

게시물 검색