Learning More Exception
Thursday, April 11, 2024 2:28 PMException
예외처리 소개
- 페이지의 전반적인
오류
에 따른 처리를 할 수 있도록 지원합니다. - 정의되어 있지 않는 경우 시스템
Exception
의 기본 예외처리를 사용합니다.
Usage
Exception별 사용방법은 다음과 같습니다.
AlertBackException
경고창에 메시지 출력 후 페이지 뒤로 가기를 실행한다.
if ($error !== false) {
// some code...
} else {
throw new AlertBackException('메시지');
}
AlertCloseException
경고창에 메시지 출력 후 브라우저를 닫는다.
if ($error !== false) {
// some code...
} else {
throw new AlertCloseException('메시지');
}
LayerException
레이어에 메시지를 출력한다.
사용예제 1
if ($error !== false) {
// some code...
} else {
throw new LayerException('메시지', null, null, $formId, $timer, $onUnBlock, $addScript, $isPrint);
}
사용예제 2
메시지가 자동으로 입력되며, 저장 후 레이어 사라지게 할 때 사용
if ($error !== false) {
// some code...
} else {
throw new LayerException();
}
AlertOnlyException
경고창에 메시지만 출력한다.
if ($error !== false) {
// some code...
} else {
throw new AlertOnlyException('메시지');
}
AlertRedirectException
경고창에 메시지 출력 후 지정된
url
로 이동한다. 타겟을 지정하면 지정된 타겟에서 url을 호출한다.
`redirect`만 원하는 경우 `controller`에서 `$this->redirect($url)`을 사용하세요.
if ($error !== false) {
// some code...
} else {
throw new AlertRedirectException('메시지', null, null, $url, $target);
}
HttpException
Request
에 대한 서버 응답코드와 메시지를 담아 지정된 에러페이지로 출력합니다.StatusCode
는 가이드 페이지 하단의Status Code
를 참고해주세요.
if ($error !== false) {
// some code...
} else {
throw new HttpException($message, 404);
}
DatabaseException
Query 실행시 발생하는
Exception
으로$e->getQuery()
로Exception
이 발생한 쿼리를 확인할 수 있습니다.
if ($error !== false) {
// some code...
} else {
try {
throw new DatabaseException($message, $code, $previouis, $query);
} catch (\Exception $e) {
printf($e->getQuery());
}
}
UploadException
파일 업로드시 사용하는 Exception으로 아래 정의된
Code
를 넣어 사용합니다.
if ($error !== false) {
// some code...
} else {
try {
// 업로드한 파일이 upload_max_filesize를 초과했습니다.
throw new UploadException(UPLOAD_ERR_INI_SIZE);
// 업로드한 파일이 지정된 파일크기보다 큽니다.
throw new UploadException(UPLOAD_ERR_FORM_SIZE);
// 파일이 일부분만 전송되었습니다.
throw new UploadException(UPLOAD_ERR_PARTIAL);
// 파일이 전송되지 않았습니다.
throw new UploadException(UPLOAD_ERR_NO_FILE);
// 임시 폴더가 없습니다.
throw new UploadException(UPLOAD_ERR_NO_TMP_DIR);
// 디스크에 파일 쓰기를 실패했습니다.
throw new UploadException(UPLOAD_ERR_CANT_WRITE);
// 확장에 의해 파일 업로드가 중지되었습니다.
throw new UploadException(UPLOAD_ERR_EXTENSION);
// 알려지지 않은 에러가 발생했습니다.
throw new UploadException('정의되지 않은 코드');
} catch (\Exception $e) {
printf($e->getMessage());
}
}
Status Code
Code | Message | Description |
---|---|---|
100 | Continue | |
101 | Switching protocols | |
200 | OK | |
201 | Created | POST 명령 실행 및 성공 |
202 | Accepted | 서버가 클라이언트 명령을 받음 |
203 | Non-Authoritative Information | 서버가 클라이언트 요구 중 일부만 전송 |
204 | No Content | 클라이언트 요구를 처리했으나 전송할 데이터가 없슴 |
205 | Reset content | |
206 | Partial content | |
300 | Multiple choices (최근에 옮겨진 데이터를 요청) | |
301 | Moved permanently | 요구한 데이터를 변경된 임시 URL에서 찾음 |
302 | Moved temporarily | 요구한 데이터가 변경된 URL에 있음을 명시 |
303 | See other | 요구한 데이터를 변경하지 않았기 때문에 문제가 있슴 |
304 | Not modified | |
305 | Use proxy | |
307 | Temporary Redirect | |
400 | Bad request | 클라이언트의 잘못된 요청으로 처리할 수 없슴 |
401 | Unauthorized | 클라이언트의 인증 실패 |
402 | Payment required | 예약됨 |
403 | Forbidden | 접근이 거부된 문서를 요청함 |
404 | Not found | 문서를 찾을 수 없음 |
405 | Method not allowed | 리소스를 허용안함 |
406 | Not acceptable | 허용할 수 없음 |
407 | Proxy authentication required | 프록시 인증 필요 |
408 | Request timeout | 요청시간이 지남 |
409 | Conflict | 프록시 인증 필요 |
410 | Gone | 영구적으로 사용할 수 없음 |
411 | Length required | |
412 | Precondition failed | 프록시 인증 필요 |
413 | Request entity too large | 요청 데이터가 너무 큼 |
414 | Request-URI too long | URL이 너무 김 |
415 | Unsupported media type | |
500 | Internal server error | 내부 서버 오류 |
501 | Not implemented | 클라이언트에서 서버가 수행할 수 없는 행동을 요구함 |
502 | Bad gateway | 서버의 과부하 상태 |
503 | Service unavailable | 외부 서비스가 죽었거나 현재 멈춤 상태 |
504 | Gateway time-out | |
505 | HTTP Version not supported | HTTP 버전 미지원 |