1. class OutOfStockException extends RuntimeException {
    2. }
    1. class OutOfStockException : RuntimeException()
    1. @Controller("/books")
    2. class BookController {
    3. @Produces(MediaType.TEXT_PLAIN)
    4. @Get("/stock/{isbn}")
    5. Integer stock(String isbn) {
    6. throw new OutOfStockException()
    7. }
    8. }
    1. @Controller("/books")
    2. @Produces(MediaType.TEXT_PLAIN)
    3. @Get("/stock/{isbn}")
    4. internal fun stock(isbn: String): Int? {
    5. throw OutOfStockException()
    6. }
    7. }
    1. @Produces
    2. @Singleton
    3. @Requires(classes = [OutOfStockException.class, ExceptionHandler.class])
    4. class OutOfStockExceptionHandler implements ExceptionHandler<OutOfStockException, HttpResponse> {
    5. @Override
    6. }
    7. }
    1. @Produces
    2. @Singleton
    3. @Requirements(
    4. Requires(classes = [OutOfStockException::class, ExceptionHandler::class])
    5. )
    6. class OutOfStockExceptionHandler : ExceptionHandler<OutOfStockException, HttpResponse<*>> {
    7. override fun handle(request: HttpRequest<*>, exception: OutOfStockException): HttpResponse<*> {
    8. return HttpResponse.ok(0)
    9. }