# Exception 소개

* 페이지의 전반적인 `오류`에 따른 처리를 할 수 있도록 지원합니다.
* 정의되어 있지 않는 경우 시스템 `Exception`의 기본 예외처리를 사용합니다.

## 📌 Usage <a href="#usage" id="usage"></a>

Exception별 사용방법은 다음과 같습니다.

### **AlertBackException**

경고창에 메시지 출력 후 페이지 뒤로 가기를 실행합니다.

```php
if ($error !== false) {
    // some code...
} else {
    throw new AlertBackException('메시지');
}
```

### **AlertCloseException**

경고창에 메시지 출력 후 브라우저를 닫습니다.

```php
if ($error !== false) {
    // some code...
} else {
    throw new AlertCloseException('메시지');
}
```

### **LayerException**

레이어에 메시지를 출력합니다.

#### **사용예제 1**

```php
if ($error !== false) {
    // some code...
} else {
    throw new LayerException('메시지', null, null, $formId, $timer, $onUnBlock, $addScript, $isPrint);
}
```

#### **사용예제 2**

메시지가 자동으로 입력되며, 저장 후 레이어 사라지게 할 때 사용합니다.

```php
if ($error !== false) {
    // some code...
} else {
    throw new LayerException();
}
```

### **AlertOnlyException**

경고창에 메시지만 출력합니다.

```php
if ($error !== false) {
    // some code...
} else {
    throw new AlertOnlyException('메시지');
}
```

### **AlertRedirectException**

경고창에 메시지 출력 후 지정된 `url`로 이동합니다. 타겟을 지정하면 지정된 타겟에서 url을 호출합니다.

{% hint style="info" %}
`redirect`만 원하는 경우 `controller`에서 `$this->redirect($url)`을 사용하세요.
{% endhint %}

```php
if ($error !== false) {
    // some code...
} else {
    throw new AlertRedirectException('메시지', null, null, $url, $target);
}
```

### **HttpException**

`Request`에 대한 서버 응답코드와 메시지를 담아 지정된 에러페이지로 출력합니다. \
`StatusCode`는 가이드 페이지 하단의 `Status Code`를 참고해주세요.

```php
if ($error !== false) {
    // some code...
} else {
    throw new HttpException($message, 404);
}
```

### **DatabaseException**

Query 실행으로 인해 `Exception`이 발생할 경우, \
`$e->getQuery()`로 `Exception`이 발생한 쿼리를 확인할 수 있습니다.

```php
if ($error !== false) {
    // some code...
} else {
    try {
        throw new DatabaseException($message, $code, $previouis, $query);
    } catch (\Exception $e) {
        printf($e->getQuery());
    }
}
```

### **UploadException**

파일 업로드시 사용하는 Exception으로 아래 정의된 `Code`를 넣어 사용합니다.

```php
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 <a href="#status-code" id="status-code"></a>

<table><thead><tr><th width="100" align="center">Code</th><th>Message</th><th>Description</th></tr></thead><tbody><tr><td align="center">100</td><td>Continue</td><td></td></tr><tr><td align="center">101</td><td>Switching protocols</td><td></td></tr><tr><td align="center">200</td><td>OK</td><td></td></tr><tr><td align="center">201</td><td>Created</td><td>POST 명령 실행 및 성공</td></tr><tr><td align="center">202</td><td>Accepted</td><td>서버가 클라이언트 명령을 받음</td></tr><tr><td align="center">203</td><td>Non-Authoritative Information</td><td>서버가 클라이언트 요구 중 일부만 전송</td></tr><tr><td align="center">204</td><td>No Content</td><td>클라이언트 요구를 처리했으나 전송할 데이터가 없슴</td></tr><tr><td align="center">205</td><td>Reset content</td><td></td></tr><tr><td align="center">206</td><td>Partial content</td><td></td></tr><tr><td align="center">300</td><td>Multiple choices (최근에 옮겨진 데이터를 요청)</td><td></td></tr><tr><td align="center">301</td><td>Moved permanently</td><td>요구한 데이터를 변경된 임시 URL에서 찾음</td></tr><tr><td align="center">302</td><td>Moved temporarily</td><td>요구한 데이터가 변경된 URL에 있음을 명시</td></tr><tr><td align="center">303</td><td>See other</td><td>요구한 데이터를 변경하지 않았기 때문에 문제가 있슴</td></tr><tr><td align="center">304</td><td>Not modified</td><td></td></tr><tr><td align="center">305</td><td>Use proxy</td><td></td></tr><tr><td align="center">307</td><td>Temporary Redirect</td><td></td></tr><tr><td align="center">400</td><td>Bad request</td><td>클라이언트의 잘못된 요청으로 처리할 수 없슴</td></tr><tr><td align="center">401</td><td>Unauthorized</td><td>클라이언트의 인증 실패</td></tr><tr><td align="center">402</td><td>Payment required</td><td>예약됨</td></tr><tr><td align="center">403</td><td>Forbidden</td><td>접근이 거부된 문서를 요청함</td></tr><tr><td align="center">404</td><td>Not found</td><td>문서를 찾을 수 없음</td></tr><tr><td align="center">405</td><td>Method not allowed</td><td>리소스를 허용안함</td></tr><tr><td align="center">406</td><td>Not acceptable</td><td>허용할 수 없음</td></tr><tr><td align="center">407</td><td>Proxy authentication required</td><td>프록시 인증 필요</td></tr><tr><td align="center">408</td><td>Request timeout</td><td>요청시간이 지남</td></tr><tr><td align="center">409</td><td>Conflict</td><td>프록시 인증 필요</td></tr><tr><td align="center">410</td><td>Gone</td><td>영구적으로 사용할 수 없음</td></tr><tr><td align="center">411</td><td>Length required</td><td></td></tr><tr><td align="center">412</td><td>Precondition failed</td><td>프록시 인증 필요</td></tr><tr><td align="center">413</td><td>Request entity too large</td><td>요청 데이터가 너무 큼</td></tr><tr><td align="center">414</td><td>Request-URI too long</td><td>URL이 너무 김</td></tr><tr><td align="center">415</td><td>Unsupported media type</td><td></td></tr><tr><td align="center">500</td><td>Internal server error</td><td>내부 서버 오류</td></tr><tr><td align="center">501</td><td>Not implemented</td><td>클라이언트에서 서버가 수행할 수 없는 행동을 요구함</td></tr><tr><td align="center">502</td><td>Bad gateway</td><td>서버의 과부하 상태</td></tr><tr><td align="center">503</td><td>Service unavailable</td><td>외부 서비스가 죽었거나 현재 멈춤 상태</td></tr><tr><td align="center">504</td><td>Gateway time-out</td><td></td></tr><tr><td align="center">505</td><td>HTTP Version not supported</td><td>HTTP 버전 미지원</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devcenter-help.nhn-commerce.com/guide/preparation/detailed-structure/exception.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
