Skip to content

Commit

Permalink
docs: RSPEC-1181
Browse files Browse the repository at this point in the history
  • Loading branch information
ssungwxx committed Mar 4, 2023
1 parent 06ac771 commit d1c15f6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions _posts/java/2023-03-04-RSPEC-1181.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Throwable과 에러는 잡지 않아야 합니다.
tags: [java, Code Smell, Major, cwe, error-handling, bad-practice, cert]
---

`Throwable` 은 자바에서 모든 에러와 예외의 슈퍼클래스입니다. `Error`는 모든 에러들의 슈퍼클래스이고 어플리케이션에 의해 잡히지 않습니다.
`Throwable` 또는 `Error`를 잡게된다면 어플리케이션이 복구 시도하지 않아야하는 `OutOfMemoryError``InternalError`도 잡게됩니다.

### 규칙을 어긴 코드

```java
try { /* ... */ } catch (Throwable t) { /* ... */ }
try { /* ... */ } catch (Error e) { /* ... */ }
// ...
```

### 규칙을 준수한 코드

```java
try { /* ... */ } catch (RuntimeException e) { /* ... */ }
try { /* ... */ } catch (MyException e) { /* ... */ }
```

### 참고

* [MITRE, CWE-396](https://cwe.mitre.org/data/definitions/396) - Declaration of Catch for Generic Exception
* [CERT, ERR08-J.](https://wiki.sei.cmu.edu/confluence/display/java/ERR08-J.+Do+not+catch+NullPointerException+or+any+of+its+ancestors) - Do not catch NullPointerException or any of its ancestors

---

If you like SONARKUBE, don't forget to give me a star. :star2:

> [원문으로 바로가기](https://rules.sonarsource.com/java/tag/bad-practice/RSPEC-1181)
> [![Star This Project](https://img.shields.io/github/stars/kantabile/sonarkube.svg?label=Stars&style=social)](https://github.com/kantabile/sonarkube)

0 comments on commit d1c15f6

Please sign in to comment.