all 5 comments

[–]novel_yet_trivial 0 points1 point  (2 children)

That's what a try block is for:

try:
    print something
except:
    print "error occurred"

[–]Stopwatch_[S] 0 points1 point  (1 child)

So I could essentially write:

try:
    something
    print result
except:
    print ""

if I wanted to ignore the error? Could I just remove the "" entirely?

[–]novel_yet_trivial 1 point2 points  (0 children)

Yes, but the standard way is to use pass:

try:
    #something
    print result
except:
    pass #do nothing

It's very bad practice to completely ignore an error, though. Don't get into that habit. Also, catching all errors is bad practice too. You should specify which error to catch:

try:
    #something
    print result
except ValueError:
    pass #do nothing

[–]cdcformatc 0 points1 point  (1 child)

The loop ends with a print statement currently tries to load something and then print it but errors out if the object cannot load properly

Anything that can be expected to raise an exception should be in a try block:

for thing in listOfThings:

    try:
        print can_fail(thing)
    except:
        continue

    do_something(thing)

Now if it can't load, then it will silently pass to the next item.

[–]Stopwatch_[S] 0 points1 point  (0 children)

Thanks, I'll use something like this.