61
slicing arrays (hexbear.net)
submitted 3 months ago by Owl@hexbear.net to c/technology@hexbear.net
you are viewing a single comment's thread
view the rest of the comments
[-] hexaflexagonbear@hexbear.net 2 points 3 months ago* (last edited 3 months ago)

At some point I'm just gonna give up and do

Try:

Entire fucking program

Except:

Print("error: something went wrong")

[-] invalidusernamelol@hexbear.net 4 points 3 months ago* (last edited 3 months ago)

Even better is to create a decorator and just wrap the offending functions:

def shut_up(func):
    def call(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            print(f"shit's fucked, but I'll be quiet about it")
            return
    return call

@shut_up
def add(x: int, y: int):
    print(x + y)

add(1, 2)
add(-1, 2)
add(1, "2")

>>> 3
>>> 1
>>> "shit's fucked, but I'll be quiet about it"

Or if you want to attempt to salvage it:

def shut_up(func):
    def call(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            try:
                return func(*map(int, args), **kwargs)
            except Exception as e:
                print(f"shit's really fucked, I even tried to fix it for you")
                return None
    return call
this post was submitted on 13 Jul 2024
61 points (98.4% liked)

technology

23238 readers
260 users here now

On the road to fully automated luxury gay space communism.

Spreading Linux propaganda since 2020

Rules:

founded 4 years ago
MODERATORS