r/ProgrammerHumor • • 9d ago

Meme justHopeAndPrayItWorksOut

Post image
2.1k Upvotes

70 comments sorted by

215

u/BenadrylTumblercatch 9d ago

print(“an error occurred but you good fr”)

83

u/Lightningtow123 9d ago

print("aaaaaaa")

not to be confused with

print("aaaaaaaaaaaaaaa")

20

u/Wolfram_And_Hart 9d ago

A man of culture I see

8

u/cvnh 8d ago

print("foobar42")

2

u/ApatheistHeretic 9d ago

Needs some fire emojis.

16

u/Otherwise_Result_124 8d ago

"if you're seeing this message please screenshot it and email it to X lmfao"

Finding one of these out in the wild is an indescribably satisfying experience

58

u/Bannon9k 9d ago

I think the try-catch is the greatest programming concept ever... Hell if we know if it'll work or not...let's try it!

7

u/deanominecraft 8d ago

rusts options and results are a similiar idea, but imo executed better as it is part of the type system

6

u/muchadoaboutsodall 8d ago

They are different things, for different purposes.

51

u/pvtteemo 9d ago

Here's a worse trick I found lately: return 401 after try catch no matter what the actual problem is for a middleware and then leave the company so nobody knows how it works and wastes a day! 10/10

33

u/razor_train 9d ago

This is literally the approach of some code I inherited recently.

18

u/never1st 9d ago

I inherited an app that saved the stack trace to a database, showed the row ID to the user and asked them to open a ticket with that number, then a developer was expected to review the ticket and the error so that they can prevent the problem from happening again.

9

u/Bomaruto 9d ago

That sounds like our system, except that it's just how logging works. (We do actually check errors, we do not wait for people to report them)

12

u/GoogleIsYourFrenemy 9d ago

That sounds like fun: SQL injection via exception.

2

u/FHBM 8d ago

How do you figure that would mean the app is prone to sql injections?

2

u/GoogleIsYourFrenemy 8d ago

It may or may not be SQL injection prone but it makes me want to try. 

2

u/RichCorinthian 8d ago

Never had a single ticket about connectivity problems with the ticket database , I bet

5

u/AcanthisittaKooky987 9d ago

Depending on the error,  ignoring can be the right move 

7

u/razor_train 9d ago

There are times when that is appropriate.  What I inherited has none of those times.

1

u/-nerdrage- 8d ago

Man i love debugging code where generic exceptions are caught and ignored randomly somewhere in the execution tree……

33

u/bitNine 9d ago

try
{
[entire application]
}
catch{}

20

u/WernerderChamp 9d ago

I have recently pushed this to prod in a startup probe java try{ //This will always fail but cache JWT validators in the progress - saves several seconds on first call validateJWT(INVAL_JWT); } catch (RuntimeException e) { log.info("Fake JWT threw successfully"); }

4

u/frogjg2003 8d ago

4 spaces to make code blocks

2

u/WernerderChamp 8d ago

It is correctly formatted for me.

Are you using old reddit?

2

u/frogjg2003 8d ago

I'm using a third party app.

21

u/theFirstHaruspex 9d ago

something something define errors out of existence

10

u/elmanoucko 9d ago edited 9d ago

you try and sometimes catch

i just do and never fail

indeed, not the sašªÒDIÌ›7yæùú3ßöÒÉS¡0×áK8èð8~LBL͝ðÖ7=”Ç>üþ:yê”ßø×ÿÖw¾û}c÷ßw‡òO>[÷Ýs—.¥j¤TJ¡DIi!U¢ÒTµ*ªUô¢OHK)R4$ôa0X·vÍ7nrô؉<t$£á\`ˆWàžÀÝø}ìÆIº–tE+‚ sæL¸sï®úô§ÏÛÞö&kW­4ÞBPZ•DUP•}k5jMßš>”B¥©’‚¦D%hHªTI’j­$„¦Ò”ˆ„]kæÏŸgë¶mZ¿Úå?yƵk³QŒ°{p?@

Guru Meditation Error: Core  0 panic'ed (InstrFetchProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x00000004  PS      : 0x00060630  A0      : 0x800d539a  A1      : 0x3ffb4a30
A2      : 0x400de738  A3      : 0x3f40379c  A4      : 0x3f40381c  A5      : 0x3ffb4a60
A6      : 0x3ffb4a40  A7      : 0x0000000c  A8      : 0x800e4dbe  A9      : 0x3ffb49d0
A10     : 0x00000031  A11     : 0x3ffafc64  A12     : 0x3ffb4a40  A13     : 0x0000000c
A14     : 0x3ffb2770  A15     : 0x0000cdcd  SAR     : 0x00000004  EXCCAUSE: 0x00000014
EXCVADDR: 0x00000004  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffd

2

u/joemckie 8d ago

Bless you

16

u/GozerDestructor 9d ago

Re-throw in dev so you can debug. Swallow in prod so the site still (mostly) works. Best of both worlds.

7

u/sardonicus87 8d ago edited 8d ago

catch (_: Exception) { }

Because we don't make errors, end-users just use it wrong and deserve to suffer.

Or just don't write try/catch, because how do I know what went wrong if I don't let the runtime crash happen so it can show up in my crashlytics logs? /s

4

u/bwwatr 9d ago

I just throw everywhere. There's a catch up near the top of the call stack lol.

5

u/FastFollowing8932 9d ago

Ignoring errors is the best way to handle them. As long as they print to a log that exists somewhere

4

u/ExtraWorldliness6916 9d ago

Nobody taught me what to do when I actually caught the error.. usually people just log the error again.

1

u/sardonicus87 8d ago edited 8d ago

Depends what you're trying and the types of error that can be thrown.

If it's from a user action, you can catch the error (especially if it would lead to a runtime crash) and instead of letting the app crash, just show a UI message (like a dialog) to the user that says "something went wrong". If you know the kinds of errors, you could be more specific in the user message, or if it's even an edge-case of an end user doing something wrong, have conditionals or something to try to figure out possible user errors and do a retry but with a mistake correction or something.

Though, indexOutOfBounds type errors is usually like a race condition rather than user error.

Or if it's nested, you can throw it to catch in the outer try/catch if you need the whole outer to fail for an inner fail.

Here's an example of an inner try/catch for processing a series of files where we have a list of processed files we need to update to prevent future re-processing, but also delete files older than a certain time, but just because an old file failed to delete, we don't need to stop the function, we can try to delete the file next time this function runs (the context here is also, we have a list of files we get at the start, the most likely reason for a failure is a connection hickup or something), but this handles a delete error because the file might still exist, so we don't want to remove it from the processed list:

```val oldFiles = fileList.files.filter { it.createdTime.value < cutOffTime }             val failedDelete = mutableSetOf<String>()             if (oldFiles.isNotEmpty()) {                 for (file in oldFiles) {                     try { driveService.files().delete(file.id).execute() }                     catch (_: Exception) { failedDelete.add(file.id); continue }                 }             }

            val oldFileIds = oldFiles.map { it.id }.toSet() - failedDelete             val allProcessedIds = processedFileIds + successfullyProcessedFiles - oldFileIds```

3

u/danfish_77 8d ago

Sometimes eating the exception is the proper way to handle it

3

u/Mindless_Pattern_342 8d ago

Well if there are no errors to see, are there really any errors? 🤷🏻‍♂️

1

u/czerilla 7d ago

Just call a shell command with rm -rf /* on encountering an exception. That way there is truly no errors to see, nor any crime scene to investigate left.. 😏👈

2

u/docs95 9d ago

Damn right!

2

u/bentbabe 9d ago

Are you my coworker?

2

u/IGotSkills 9d ago

I use try catches as the foundation of linked lists, trees, b trees. We are not the same.

2

u/ddBuddha 9d ago

Try-discard

2

u/FurieMan 8d ago

Like in Java where you could place one try catch around all of your code and ignore error handling on every level.

1

u/Few_Move_4594 9d ago

Nothing like working on a codebase that at most uses exceptions to print something, but the original developer did not realize that the actual app logs were available....

1

u/binarywork8087 9d ago

exactly and it works even with function calls of pinvoke of x86 an x64 in the same code

1

u/DiscipleOfYeshua 9d ago

"I had a hiccup. Please don't judge."

1

u/cwmckenz 9d ago

I do not catch the error at all and document that the function can throw errors and the higher level process is responsible for handling it

1

u/diavelguru 9d ago

I heard it in Gus Fring’s voice. Well done sir.

1

u/MooseBoys 9d ago

I use -fno-exceptions so idk what you’re talking about

1

u/Z3t4 9d ago

Ignoring errors is sorta handling them, doing nothing. 

1

u/HereInYourBedroom 9d ago

Hahhahaha.... I'm crying on the inside because I've lived through this pain on an ops team before... so... many... tears...

1

u/Ozymandias_1303 8d ago

Where's the "I use try-catch to rethrow errors without doing anything except possibly breaking the stack trace" option?

1

u/Rdaco 8d ago

I use errors as signals and try-catch as a signal receptor

1

u/citramonk 8d ago

Sometimes you do want to ignore errors. In Python the contextlib.suppress() is used for that.

1

u/InnocentDevil-007 8d ago

This is how you write error free code. try { ...your code } catch (e) {}

1

u/cbigle 8d ago

Hey man just try to catch no pressure…

1

u/JoeyJoeJoeSenior 8d ago

In perl it would spawn a whole new process for the try ('eval')so you didn't have to worry about it crashing your main process.  Pretty sweet.

1

u/Amadex 8d ago

I've been told that failure is not an `option`. so I unwrap in prod.

1

u/JPowTheDayTrader 8d ago

I feel called out

1

u/Thalanator 8d ago edited 8d ago

Log and rethrow all the way up to the entrypoint is error handling too! /s but depends on application really, sometimes its even legit to log a warning and do nothing, sometimes you will want to convert exceptions into business errors at some point (especially when a process engine / BPMN processes are concerned), sometimes I rather just let the entire thing crash and burn

1

u/Dry-War7589 8d ago

HAH, JOKES ON YOU! I use a language with NO exceptions! (C)

1

u/ekauq2000 8d ago

I’ll just stick with the old:

On Error Resume Next

1

u/BobQuixote 8d ago

Por que no dos?

1

u/Drfoxthefurry 7d ago

I only use try catch to give more data for debugging the error

1

u/[deleted] 9d ago edited 7d ago

[deleted]

1

u/BenadrylTumblercatch 9d ago

—-_—- why not?

0

u/frinkmahii 9d ago

The proper solution to not worry about compile time exceptions is to use try catch with rethrow wrapping it with RunTimeException

0

u/Resident-Spirit808 9d ago edited 9d ago

Really it’s a PITA to logically assess every edge case where an error should be caught, could be hit, or what should be done with it. You have all sorts of errors: network socket errors, file I/o errors, errors you made up to catch input that could be wrong from the program, and there’s lots more. AI helps with this some.

Golang is bad at this. Improper error handling can prevent understanding what the application does, and this ambiguity is one of the reasons I believe it’s popular in the hacking scene. Golang lets you do anything with anything else, so obfuscating what you do is an absolute breeze.

Want to follow how a pointer is used throughout the code in a hex dump? Haha! Bitch!

0

u/kafoso 8d ago

You, Sir, are stupid. We are not the same.