Skip to content

Unnecessary try-catch instead of validation #4

@AlexBen

Description

@AlexBen

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)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions