r/ProgrammerHumor • • Jul 20 '18

Every Time

Post image
52.2k Upvotes

749 comments sorted by

View all comments

Show parent comments

457

u/Kidiri90 Jul 20 '18
if(DateTime.Now.Milliseconds%2==0)
{
    throw new Exception("lol screw you:);
}

154

u/plexxonic Jul 20 '18

I need to hide this in commits.

94

u/[deleted] Jul 20 '18

Hide it in a third party library that you snuck back into Artifactory.

0

u/[deleted] Jul 20 '18

[deleted]

53

u/[deleted] Jul 20 '18

Changing it to mod 31 might prevent someone finding it while it's in debug, but it's still an exception so there's still going to be a stacktrace that points you directly to it. Doesn't matter if the error message is searchable.

0

u/[deleted] Jul 20 '18

[deleted]

27

u/LvS Jul 20 '18

You can see the stacktrace from where your code died.

In C you could mess with the stack pointer and then jump to a random address, but even that can be caught with tools like rr.

What you want to throw is a DNS lookup failure or something that just happens regularly in that piece of code.

12

u/Hdmoney Jul 20 '18

The real way to do it would be by invalidating state in a way that you know will get caught in the future.

3

u/SheepLinux Jul 20 '18

I feel sorry for whoever has to debug/deploy ur horrible horrible mess lol

7

u/FatFingerHelperBot Jul 20 '18

It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!

Here is link number 1 - Previous text "rr"


Please PM /u/eganwall with issues or feedback! | Delete

→ More replies (1)
→ More replies (2)

14

u/Kalabasa Jul 20 '18

You can modify the exception's stack trace before throwing.

9

u/[deleted] Jul 20 '18

Wait really? I’ve never seen that or thought to do that before. I guess if people ever do that it’s usually to help debug rather than modify it with malicious intent

10

u/Kalabasa Jul 20 '18

Yeah, at least in Java. I guess it's for frameworks to hide internal stuff (cut off the part of the trace

4

u/citewiki Jul 20 '18

Cutting off... like the parenthes

→ More replies (1)
→ More replies (1)
→ More replies (3)
→ More replies (2)

25

u/WiseassWolfOfYoitsu Jul 20 '18

Although it's a bit aggressive. %2 would be 50% of the time, which would be fairly easy to solve. Also just in one place. I prefer:

#define true (rand() % 10000 == 0)

15

u/slashuslashuserid Jul 20 '18

don't forget to seed that though, and also yours will be triggered 99.99% of the time, not 0.01%

 #include<stdlib.h>
 #include<time.h>
 srand((unsigned int)time(0));
 #ifdef true
     #undef true
 #endif
 #define true (rand() % 10000)

5

u/WiseassWolfOfYoitsu Jul 20 '18

and also yours will be triggered 99.99% of the time, not 0.01%

'doh :)

→ More replies (1)
→ More replies (1)

20

u/[deleted] Jul 20 '18

Wouldn't the stacktrace lead you exactly to this? Meaning it would be confusing/amusing once?

24

u/DoctorWaluigiTime Jul 20 '18

Technically, currently as-written, it wouldn't compile!

15

u/normalmighty Jul 20 '18

You must have missed the hip new wave of languages that close strings with a colon so you can tell the open and close strings apart.

4

u/[deleted] Jul 20 '18

Would be better to null out an important object from some class that is only barely related.

→ More replies (3)

6

u/I_am_the_inchworm Jul 20 '18

Next level:

Import the string from a project-external resource, don't want a simple project-wide search to show it.

4

u/_realitycheck_ Jul 20 '18

You forgot this: "

3

u/Kidiri90 Jul 20 '18

That's what I get from doibg it ob movile.

→ More replies (3)
→ More replies (1)