-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
> [](https://github.com/kantabile/sonarkube) |