PHP Exception 클래스
PHP/매뉴얼 번역 2008/05/07 23:20- Exception 클래스는 모든 예외들의 베이스클래스 (Exception is the base class for all Exceptions.)
- Exception 베이스 클래스의 기본 구조는 다음과 같음.
class Exception {
/* 속성 */
//예외 메시지
protected string $message ;
//내부 예외명
private string $string ;
//예외 코드
protected int $code ;
//예외가 throw 된 파일명
protected string $file ;
//예외가 throw 된 행번호
protected int $line ;
//스택트레이스
private array $trace ;
/* 메소드 */
public __construct ([ string $message [, int $code ]] )
final public string getMessage ( void )
final public int getCode ( void )
final public string getFile ( void )
final public string getLine ( void )
final public string getTrace ( void )
final public string getTraceAsString ( void )
/* Overrideable */
public string __toString ( void )
final private string __clone ( void )
}
- Exception::__construct([ string $message [, int $code ]] )
예외를 작성
설명
string $message스로(throw) 하는 예외 메시지
int $code예외 코드
- Exception::getMessage ( void )
예외 메시지를 리턴
예)
try {
throw new Exception("Some error message");
} catch(Exception $e) {
echo $e->getMessage();
}
- Exception::getCode ( void )
예외코드를 리턴
try {
throw new Exception("Some error message", 30);
} catch(Exception $e) {
echo "The exception code is: " . $e->getCode();
}
The exception code is: 30 - Exception::getFile ( void )
예외가 발생한 파일명 리턴
try {
throw new Exception;
} catch(Exception $e) {
echo $e->getFile();
}
/home/bjori/tmp/ex.php
- Exception::getLine ( void )
예외가 발생한 행번호 리턴
try {
throw new Exception("Some error message");
} catch(Exception $e) {
echo "The exception was thrown on line: " . $e->getLine();
}
The exception was thrown on line: 3
- Exception::getTrace ( void )
예외의 스택트레이스를 리턴
배열값 리턴
function test() {
throw new Exception;
}
try {
test();
} catch(Exception $e) {
var_dump($e->getTrace());
}
array(1) {
[0]=>
array(4) {
["file"]=>
string(22) "/home/bjori/tmp/ex.php"
["line"]=>
int(7)
["function"]=>
string(4) "test"
["args"]=>
array(0) {
}
}
}
- Exception::getTraceAsString ( void )
예외의 스택트레이스의 문자열 리턴
문자열값(스트링) 리턴
function test() {
throw new Exception;
}
try {
test();
} catch(Exception $e) {
echo $e->getTraceAsString();
}
#0 /home/bjori/tmp/ex.php(7): test()
#1 {main}
- Exception::__toString ( void )
예외의 문자열 표현값을 리턴
try {
throw new Exception("Some error message");
} catch(Exception $e) {
echo $e;
}
exception 'Exception' with message 'Some error message' in /home/bjori/tmp/ex.php:3
Stack trace:
#0 {main}
- Exception::__clone ( void )
예외의 복사본(클론)을 작성하는 메소드.
결과적으로는 Fatal 에러발생
예외는 클론 불가능.
- Exception::__construct([ string $message [, int $code ]] )
영어 페이지 : http://jp.php.net/manual/en/class.exception.php
한글 페이지는 없음.
목차로
PHP 예외 매뉴얼 번역
'PHP > 매뉴얼 번역' 카테고리의 다른 글
| PHP 스코프 연산자(::) (0) | 2008/06/19 |
|---|---|
| PHP 억세스권(접근권한) : Visibility (0) | 2008/06/19 |
| PHP 컨스트럭터와 디스트럭터 (0) | 2008/06/19 |
| PHP 오브젝트의 오토로딩 (0) | 2008/06/19 |
| PHP 클래스의 기초 (0) | 2008/06/19 |
| PHP 클래스와 오브젝트 ( Classes and Objects ) PHP 5 (0) | 2008/06/19 |
| PHP 언어레퍼런스 예외(exceptions) (0) | 2008/06/17 |
| PHP ErrorException 클래스 (0) | 2008/06/17 |
| PHP 예외 매뉴얼 번역 (0) | 2008/06/17 |
| PHP Exception에 관하여... (0) | 2008/06/17 |
| PHP Exception 클래스 (0) | 2008/05/07 |