this post was submitted on 12 May 2024
514 points (97.1% liked)

Programmer Humor

32410 readers
1 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] prof 78 points 1 year ago (28 children)

Meme is funny, but that exception used as flow control hurts.

[–] wizardbeard@lemmy.dbzer0.com 11 points 1 year ago (4 children)

Still hurts, but sometimes it's the only option.

If you're trying to confirm things like account existence/deletion, there's often no "account exists" function to return true or false. You just have to figure out the specific exception thrown and catch that specific one.

The worst are libraries that don't give specific exceptions, so you have to catch all exceptions then do extra work to tell what the specific situation is. Does the account not exist, or is the system unreachable?

[–] prof 3 points 1 year ago

Yeah, I had a similar case with some authentication middleware I used that was part of a library.

It would always throw an exception when a user wasn't authenticated instead of just giving me some flag I could check.

Wouldn't have done it that way, but it was okay for an API controller.

load more comments (3 replies)
load more comments (26 replies)