title: Kotlin - Spring REST - ControllerAdvice with ExceptionHandler won't get invoked
body: <p>In order to simplify my error handling i wanted an ExceptionHandler, i have used the 4. point on <a href="http://www.baeldung.com/exception-handling-for-rest-with-spring" rel="noreferrer">http://www.baeldung.com/exception-handling-for-rest-with-spring</a> .</p>
  
  <p>My exception handler class looks like follows:</p>
  
  <pre><code>@ControllerAdvice
  class APIExceptionHandler : ResponseEntityExceptionHandler() {
  
      @ExceptionHandler(value = [(TestException::class)])
      fun handleConflict(exception: TestException, request: WebRequest): ResponseEntity&lt;Any&gt; {
          println("Handle")
          return handleExceptionInternal(exception, "Response Body", HttpHeaders(), HttpStatus.BAD_REQUEST, request)
      }
  }
  </code></pre>
  
  <p><code>TestException</code> is just a simple <code>Exception</code> that extends <code>RuntimeException</code></p>
  
  <pre><code>class TestException : RuntimeException()
  </code></pre>
  
  <p>Anyhow, in my <code>RestController</code> i am simply throwing an exception as soon as any call is made:</p>
  
  <pre><code>@GetMapping("/lobby/close")
  fun closeLobby(@RequestParam(value = "uuid") uuid: String, @RequestHeader(value = "userSession") userSession: String): ResponseEntity&lt;Any&gt; {
      throw TestException()
  }
  </code></pre>
  
  <p>But the exception handler is not invoked.</p>
  
  <p>However, calling this:</p>
  
  <pre><code>@GetMapping("/lobby/error")
  fun error(): ResponseEntity&lt;Any&gt; {
      throw TestException()
  }
  </code></pre>
  
  <p>it is invoked.</p>
  
  <p>I don't quite understand what the difference is, besides of the first version expecting parameters and a specific header.</p>
  
  <p><strong>UPDATE 24.03.2018</strong></p>
  
  <p>The problem seems to be, that the ExceptionHandler isn't being invoked if the clients request was malformed. </p>
  
  <p>By default a malformed request leads to a pretty detailed error report, but the custom ExceptionHandler seems to disable this functionality.</p>