thiagoretondar
04/21/2019, 10:34 PMthis.repository.findByIdOrNull
and when programming in Java I throw a Custom Exception (ResourceNotFoundException
for example). What is a best practice to do this in Kotlin?dan.fritz
04/22/2019, 12:59 AMval name = node.getName() ?: throw IllegalArgumentException("name expected")
thiagoretondar
04/22/2019, 1:17 AMJukka Siivonen
04/22/2019, 9:06 AMJukka Siivonen
04/22/2019, 9:08 AMthiagoretondar
04/22/2019, 10:15 AMthis.repository.findByIdOrNull
and in case receive null throws an Exception ResourceNotFoundException
to the controller layerMike
04/22/2019, 12:09 PMvbsteven
04/23/2019, 6:48 AMResourceNotFoundException
in the service layer by using the elvis operator after findByIdOrNull()
, the exception is handled by a @ControllerAdvice
class.
If the absence of a value is not fatal I will just return the nullable value to the controller and have the controller handle the presence/absence check.