Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- servlet프로젝트
- 코틀린
- jsp프로젝트
- 백준
- 트랜잭션속성
- Google Place Photo API
- 코틀린뽀개기
- mysqld.sock
- 자바비동기
- 데이터베이스락
- 테코톡
- 코틀린기초
- 무중단배포
- S2139
- 트랜잭션성질
- DynamicWebProject
- java
- GithubOAuth
- 객체지향생활체조
- 리버스프록시
- 스프링트랜잭션
- 레벨로그
- 알고리즘
- subprocess에러
- ObjectCalisthenics
- KotlinInAction
- 우아한테크코스
- 트랜잭션
- kotlin
- tomcat설정
Archives
- Today
- Total
초이로그
[SonarLint] 예외는 로그로 남기던가 다시 던져야한다. 그러나 둘 다 하면 안된다(java:S2139) 본문
Exceptions should be either logged or rethrown but not both
In applications where the accepted practice is to log an Exception and then rethrow it, you end up with miles-long logs that contain multiple instances of the same exception. In multi-threaded applications debugging this type of log can be particularly hellish because messages from other threads will be interwoven with the repetitions of the logged-and-thrown Exception. Instead, exceptions should be either logged or rethrown, not both.
Code Smell: 🚫 Major
애플리케이션의 try-catch문에서 예외를 로그로도 기록하고 다시 던지면, 똑같은 예외의 인스턴스를 갖는 매우 긴 로그가 생성된다. 멀티 스레드 애플리케이션 환경에서는 다른 스레드의 로그와 예외가 섞여서 디버깅하기가 매우 힘들어진다. 그러니 예외는 로그로만 남기거나 또다른 예외로 던지기 둘 중하나만 하자.
잘못된 코드 예시
catch (SQLException e) {
...
LOGGER.log(Level.ERROR, contextInfo, e);
throw new MySQLException(contextInfo, e);
}
좋은 코드 예시
catch (SQLException e) {
...
throw new MySQLException(contextInfo, e);
}
catch (SQLException e) {
...
LOGGER.log(Level.ERROR, contextInfo, e);
// handle exception...
}
출처
'Stacks' 카테고리의 다른 글
[Google Maps API] Place Photo API 사용방법 (0) | 2021.08.06 |
---|---|
[Git] 폴더이름이 한글일때 오류 (0) | 2021.04.22 |
[Ubuntu] mysql, mariadb /usr/bin/dpkg 에러해결 (0) | 2020.07.28 |
[Grafana]Grafana에 MongoDB 데이터 불러오기 (0) | 2020.07.24 |