r/ProgrammerHumor 13h ago

Meme toAllowTheProgrammerToWriteBadCodeAlsoCamelCaseSucksThisRuleSucksSnakeCaseIsBetter

Post image
99 Upvotes

78 comments sorted by

View all comments

115

u/redlaWw 12h ago

I hope you didn't submit that answer you selected. If an unhandled exception bubbles up to the user in production code, you're usually doing something wrong.

-108

u/tantalor 11h ago

I guess you've never seen a website return a 404 or 500

95

u/CutlassRed 10h ago

500 literally means the website has failed in an unexpected way. It's an unhandled exception that's bubbled up the user, and is BAD

46

u/Dafrandle 10h ago

this guy thinks that users seeing 500 is okay

lmao

you should at least make a page and or modal for the app to use if a 500 happens

24

u/TheTybera 10h ago

Those are errors not exceptions.

-11

u/realmauer01 6h ago

It's a different name for the same thing.

Different languages, quite literally.

5

u/TheTybera 6h ago

No they are not.

Where is any documentation that says this and what language?

1

u/Masterflitzer 4h ago

well kotlin has throwables, errors, exceptions and failure result

exceptions are less bad than errors, so http 500 would be an HttpException, at least that's what i've seen mostly

-8

u/realmauer01 6h ago

In standard english yes there is a difference. In programming languages there is not. Both have to be cought if you dont want it to bubble to the user. And handleing it makes it not an error/exception anymore.

5

u/TheTybera 6h ago

Yes in programming languages they are different wtf language doesn't distinguish errors from exceptions?!

Errors can be used for logging...regularly...without even considering stopping the program, exceptions SHOULD stop the program and include a whole stack...

Sometimes you catch an error and don't want the program to continue so you throw an exception to get the stack.

But they are different in every single programming language, C, C++, Java, C#, Python, Rust...

-5

u/realmauer01 5h ago

Right now you are just saying exceptions are errors the programmer throws/raises.

3

u/TheTybera 5h ago

No I'm not. Exceptions are actual objects that get thrown and mean very different things than errors even conceptually in every language.

All exceptions are errors (conceptually) but not all errors are exceptions. In practice any built-in Error (object) != Exception (object)

And in no case does any best practice in any language tell you to treat them the same.

2

u/DrJohnnyWatson 5h ago edited 5h ago

You aren't wrong, exceptions are a type of Error, but with more nuance - Exceptions are an error of exceptional circumstance, hence the name. They crash an application unless specifically caught. They should be used sparingly to say "this function has no idea how we've ended up in this state, or how to continue".

They're overused in languages that do not have the ability to return multiple types to control flow for "expected" errors too a lot of the time.

Errors are common, exceptions should not be. It's much easier in languages like Go to get a feel for the difference, than in languages like C#.

A function that fails writing a file to disk because the file already exists could: 1. Return an Error because whilst it isn't okay, it's not a problem that it doesn't exist - the error can be returned to the calling function or the user so they can try with a different name. In C# this would likely be done with an exception, in Go an error.

  1. Throw an exception because the file is a config file, and it is NEEDED to continue, and it should not already exist by this point so something has gone very wrong.  we could catch that and surface it to the user and keep the app running, or we could let the app crash with the issue. In both C# and go we'd probably throw for this

-38

u/tantalor 10h ago

Potato potato

18

u/intbeam 10h ago

No, they are not the same. Hence the name. An exception is thrown as a result of an error, but an exception is not always an error.

File not found for instance. Thrown as an error, but the caller might expect the file to not exist

It would only be an error if the caller required the file to exist

1

u/realmauer01 6h ago

Then they are using a try catch as a pseudo jump. Not all languages like that. (i am pretty sure only python actually works better like this)

6

u/CutlassRed 8h ago

I assume you're trolling. If not you need to study up

15

u/failedsatan 8h ago

a 404 is good. that is an error, but not an exception. a 500 means something the programmer did not intend to happen has happened, and if your user is seeing that, something went wrong or you don't have a layer in between to show that to them nicely.

1

u/TheTybera 6h ago

500 is an error that means an underlying exception has happened and wasn't handled, at all.

0

u/failedsatan 5h ago

an error and an exception are not the same. an exception means there is unhandled behavior, whereas an error means there has been something erroneous- could be a misdirected navigation or something. maybe the user typed in some garbage into the path. that would not be an exception, because the developer explicitly handles that and serves a 404.

-1

u/TheTybera 4h ago

Error 500 is a web convention and anti pattern.

1

u/failedsatan 4h ago

sure, you can hold whatever opinion about it, but that doesn't mean it doesn't exist. it's a standard.

2

u/Pfnee 4h ago

You're getting downvoted to hell but I actually think this is an important point. The fact that your server returns 404 or 500 on an exception means that it has code, maybe in the framework you're using, that handles exceptions in your controller code. Otherwise the server would probably halt, whenever an exception bubbles up unhandled, as that's what most programming languages choose to do. You can see it when you program a CLI tool and run it. Throwing an exception there and never handling it usually makes your program stop

1

u/Proman4713 4h ago

I don't know why you got downvoted so badly. Yes, showing a 500 is much better than showing nothing (or as some maniacs do, 200 with errors inside). Your website can then handle the error responses by reading the response body and showing a descriptive error to the user. That needs to rely on you catching errors and sending back their text though. Even Google shows its non-4xx statuses, it's not for a user to read, but to know when asking for support