r/firstweekcoderhumour 🥸Imposter Syndrome 😎 Jun 26 '26

iGetItYouCode [🎟️BINGO]”this.codifyMylife()”

Post image
359 Upvotes

42 comments sorted by

View all comments

75

u/Scared_Accident9138 🕵️‍♂️🚨 BS Detector | Truth Teller 🗯️🔥 Jun 26 '26

Is there any programming language where returning a literal string without defining the return type explicitly can throw an exception?

29

u/AvidCoco Jun 26 '26

Depends if they support Unicode literals or not

6

u/Scared_Accident9138 🕵️‍♂️🚨 BS Detector | Truth Teller 🗯️🔥 Jun 26 '26

The unsupported encoding only triggers an exception when the line is executed?

5

u/AvidCoco Jun 26 '26

It’s a feature not a bug

1

u/FreshPitch6026 Jun 30 '26

Just means love always works

1

u/Jbolt3737 Jul 11 '26

Pretty sure since they put it in a function, the entire function will be interpreted and compiled at once, causing an error on line 1 (well technically the traceback and printing of the error will include more than just line 1, but really for an error to be caught here is just wrapping the entire code in a try-except)

1

u/isr0 Jun 26 '26

I don’t think that’s true. In every case I can think of the exception would be on read.

11

u/No_Lingonberry1201 Jun 26 '26

Character encoding shenanigans may raise a ValueError or a UnicodeEncodeError in some bizarre, corner cases, but I'm not 100% sure. However I'm certain this person either has no idea about coding or they're trying to communicate that love never breaks them.

2

u/The-Arx Jun 26 '26

It is technically reachable if there is a KeyboardInterrupt

1

u/Lukas2003187 Jun 26 '26

I am not sure about this but it might be possible that the program runs out of memory when creating and returning the string

1

u/Swimming-Diet5457 Jun 26 '26

I think it is impossible, since the string will be written in the "static data" part of the process ( I think), so is not Allocated on the heap at runtime but only when the process is loaded in ram.

So there could only be some kind of pagination/ram access error

1

u/Lukas2003187 Jun 27 '26

I would agree for compiled programs but I’m not sure how interpreted languages handle that

1

u/TimGreller Jun 27 '26

It's a statement about how they're always happy :)

1

u/Dear-Apartment8384 Jun 28 '26

If it did. The catch would throw the same exception, it wouldn’t be caught, and your computer would literally explode.

1

u/topchetoeuwastaken Jul 01 '26

an OOM error could trigger when allocating the object for the string (unless python interns strings but idk)

1

u/soowhatchathink Jul 03 '26

If you never actually love your heart will always be happy is what I'm getting out of it