Search code examples
springkotlinexceptionjpahexagonal-architecture

Where should exceptions be throwed in a hexagonal architecture?


I'm changing 3 layer architecture to hexagonal architecture. In hexagonal, Should the exception be throwed in the adapter or in the service?

This is code I write. I use Kotlin, Spring, JPA. Once I throw exception in service. (EntityNotFoundException)

give me feedback!


Solution

  • Might this will help!

    • Domain Layer

      • InvalidOrderStateException,
      • InsufficientBalanceException
    • Application Layer

      • Catching a DatabaseConnectionException and throwing a DataAccessException.
    • Adapter Layer

      • EntityNotFoundException
      • DatabaseConnectionException