custom exception을 언제 써야 할까?우아한테크코스의 두 크루인 오렌지와 우가 싸우고 있다. 왜 싸우고 있는지 알아보러 가볼까? 오렌지 : 아니 굳이 사용자 정의 예외 안 써도 됩니다!! 우 : 아닙니다!! 써야 합니다!!! 사용자 정의 예외(Custom Exception) 에 대한 둘의 의견이 좁혀지지 않는다. 각자의 주장을 더 자세히 들어보자! 커스텀 예외의 장점으로 예외클래스의 이름만으로 어떤 예외인지 알아보기 쉽다는 점을 꼽는다.https://tecoble.techcourse.co.kr/post/2020-08-17-custom-exception/Spring Exception HandlingJava 에는 Checked Exception 과 Unchecked Exception 이 존재합니다. 이 둘은 헷갈리기 쉽지만 사실 큰 차이가 존재합니다. 예외 처리 필수 try catch 로 잡아서 예외를 처리하거나 상위 메소드로 넘겨줘야함 Transaction 기본 롤백 대상이 아니라서 롤백 처리하려면 추가 처리 필요 컴파일 단계에서 체크 예외 처리 필수 아님 Transaction 롤백 대상 @Transactional rollbackFor 에 기본 옵션으로 들어가있기 때문에 예외 발생 시 롤백 처리됨 런타임 단계에서 체크 Spring 에는 HTTP Status 응답 처리를 위한 여러가지 방법이 있습니다.https://bcp0109.tistory.com/303Spring Guide - Exception 전략 - Yun Blog | 기술 블로그스프링은 예외처리를 위해 다양하고 막강한 어노테이션을 제공하고 있습니다. 일관성 있는 코드 스타일을 유지하면서 Exception을 처리하는 방법에 대해서 소개하겠습니다. Error Response 객체는 항상 동일한 Error Response를 가져야 합니다. 그렇지 않으면 클라이언트에서 예외 처리를 항상 동일한 로직으로 처리하기 어렵습니다. Error Response 객체를 유연하게 처리하기 위해서 간혹 Map 형식으로 처리하는데 이는 좋지 않다고 생각합니다.https://cheese10yun.github.io/spring-guide-exception/#null자바 예외 구분: Checked Exception, Unchecked ExceptionChecked Exception과 Unchecked Exception의 차이를 알아보기 전에 먼저 예외와 에러가 무엇인지 알아볼 필요가 있다. 프로그래밍에서 예외(Exception) 란 입력 값에 대한 처리가 불가능하거나, 프로그램 실행 중에 참조된 값이 잘못된 경우 등 정상적인 프로그램의 흐름을 어긋나는 것을 말한다. 그리고 자바에서 예외는 개발자가 직접 처리할 수 있기 때문에 예외 상황을 미리 예측하여 핸들링할 수 있다.https://madplay.github.io/post/java-checked-unchecked-exceptions Top 20 Java Exception Handling Best Practices - HowToDoInJavaThis post is another addition in best practices series available in this blog. In this post, I am covering some well-known and some little known practices which you must consider while handling exceptions in your next java programming assignment. Follow this link to read more about exception handling in java.https://howtodoinjava.com/best-practices/java-exception-handling-best-practices/Understanding Java Exception Chaining with Code ExamplesThis Java tutorial helps you understand the concept of exception chaining (or exception wrapping, exception propagation) and apply it to your Java daily coding. Basically, exception chaining is the process of re-throwing multiple exceptions across different abstraction layers of a program.https://www.codejava.net/java-core/exception/understanding-java-exception-chaining-with-code-examplesException Handling in Spring MVCNOTE: Revised April 2018 Spring MVC provides several complimentary approaches to exception handling but, when teaching Spring MVC, I often find that my students are confused or not comfortable with them. Today I'm going to show you the various options available. Our goal is to not handle exceptions explicitly in Controller methods where possible.https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc