title: 500 Internal Server Error instead of 404 in Spring Boot
body: <p>When I try to find out the value that is not there in the database I get 500 Internal Server Error. I have already provided logic to throw <code>ResourceNotFoundException</code> error, but, it's not working for some reason. What do I need to do to get <code>404 ResourceNotFoundException</code> instead of <code>500 Internal Server Error</code>.
  Here's my code:</p>
  
  <pre><code>@PostMapping("/start/{id}")
      public ResponseEntity&lt;String&gt; startEvent(@PathVariable() Long id) {
          Event event = this.eventRepository.findById(id).get();
  
          if (event == null) {
              throw new ResourceNotFoundException("Event with id " + id + " not found.");
          }
  
          event.setStarted(true);
          this.eventRepository.save(event);
  
          return ResponseEntity.ok("Event " + event.getName() + " has started");
      }
  </code></pre>
  
  <p>I guess eventRepository.findById(id)   //id = 200 returns 500 response as record with id 200 does not exist in the database. What should I do to get   ResourceNotFoundException?</p>