1

I am following this spring.io tutorial. There is a function like this:

@RequestMapping(method = RequestMethod.GET)
    Collection<Bookmark> readBookmarks(@PathVariable String userId) throws UserNotFoundException {
        this.validateUser(userId);
        List<BookmarkResource> bookmarkResourceList = bookmarkRepository.findByAccountUsername(userId).stream().map(BookmarkResource::new).collect(Collectors.toList()) ;
        return this.bookmarkRepository.findByAccountUsername(userId);
    }

Although I had thrown the UserNotFoundException at the function signature, it still has Unhandled Exception at the double colons. I don't know how to throw that exception. Sreenshot of UnhanledException Any help would be appreciated!

pvpkiran
  • 23,183
  • 6
  • 71
  • 112
Andiana
  • 1,852
  • 4
  • 31
  • 69

1 Answers1

2

In Java 8 Streams, you can't use methods that throw checked exceptions. You can wrap the code in try/catch, or throw an unchecked exception.

For a comprehensive answer, please see this question.

Ondra K.
  • 2,367
  • 3
  • 21
  • 38