r/AskProgramming • • Jul 11 '26

When to use try/except vs if/else

I was making a simple program when I wondered when to use try and except this is the code I'm looking at.

if (Path.home() / "Desktop").exists():
        desktop_path = Path.home() / "Desktop"
else:
        desktop_path = Path.home() / "OneDrive/Desktop"
4 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/HashDefTrueFalse Jul 11 '26

Ah, I haven't written Python in years. Didn't think you could do a concat like this: Path.home() / "Desktop" Don't remember seeing that before.

1

u/wildsoup1 Jul 13 '26

Pathlib was introduced in Python 3.4 (2014).