Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary try-catch instead of validation #4

Open
AlexBen opened this issue Apr 4, 2020 · 1 comment
Open

Unnecessary try-catch instead of validation #4

AlexBen opened this issue Apr 4, 2020 · 1 comment

Comments

@AlexBen
Copy link

AlexBen commented Apr 4, 2020

Hello Stephane, I'm taking your course right now, and during it just found the approach you use, which in my opinion could be improved.
I understand that the course is not about "good practices" or "java coding", but since the students could refer to this code, it makes sense to use best practices.

In this case, ObjectId has a static method #isValid, and we can make this check (with returning INVALID_ARGUMENT status) instead of naive try-catch.

result = collection.find(eq("_id", new ObjectId(blogId)))

@simplesteph
Copy link
Owner

hey thanks for the feedback! I'm certain the code could be improved here and there, but I can't change it right now as this wouldn't match the video recording. Hope you understand :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants