Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Exceptions

Name: newfag 2012-04-22 10:59

What is the best way of dealing with invalid argument?
Throw an exception or return null?

Lets have an example. I was writing this function that
creates date objects for dates in between 2000-01-01 and
2999-12-31

Looks like this:
<code>
def createDate(date):
    try:
        y, m, d = date
        if(y < 0): return None
        if(y < 2000): y += 2000
        if(y > 2999): return None
        return datetime.date(y, m, d)
    except ValueError:
        return None
</code>

What should i do here? Should i just let the ValueError
error propagate up the stack, maybe throw my own ValueError exceptions in stead of returning None or should i
invent my own exception and throw that instead of ValueError,
or just leave it as it is?


What would you do?

>in b4 "dat shitty language"

Name: Anonymous 2012-04-22 18:11

dying is not an exceptional event, you being reborn after being [i]freed[i] is
No, being reborn is not an exceptional event either, because there is no such thing. The only enlightenment that exists is realizing there is no enlightenment, it's all in your head, realizing you really are not intelligent, artistic or a beautiful unique snowflake, no one gives enough fucks about you to stalk you, no one will ever understand you, you will never understand anyone, you will never understand yourself, only you can cure your depression, you can never get "out of the box" because there is no fucking box, your ego will never be destroyed except when you die, you will not only eventually die but it will happen meaninglessly because that's how you define meaning, there is no such thing as true love or friendship, everything is a little bit shit, and to make something less shit something else has to be made more shit, but making something more shit does not mean making something else less shit, you will always want only what you cannot have, there is no "true identity", you are always part of the mainstream, other people will always influence your choices and thinking, you define all the patterns in the chaos, only you can dominate yourself, you define all concepts, you will always suck and be a loser because that's how you define sucking and being a loser, you will never quit 4chan, you will always be paranoid, you will always be obsessive, you will never travel in space/time, and most importantly, you are a silly boy. The holy night does not shine.

"You sure you want to be free? You've been free already." -Timothy Leary

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List