News for hackers. Stuff that matters.
Re:Rust for Python Programmers by Grue3 on Wednesday May 27, 2015 @08:29AM (#9610849)
>To be fair, the adorable `except:` black magic exists there to be used in such a case. Of course its use is extremely dangerous for obvious reasons (it even catches the `SystemExit` exception!), so I can understand why the author didn't mention this.

This is why you use "except Exception:" which doesn't catch system exceptions.

Re:Rust for Python Programmers by themartorana on Wednesday May 27, 2015 @11:01AM (#9611832)
I think the point was (and I'm extrapolating here) that `except:` exists at all, and doesn't require any special foresight to use. That compared to Rust, which thinks about safety first.

Or so it seemed to me.

Re:Rust for Python Programmers by wyldfire on Wednesday May 27, 2015 @12:10PM (#9612359)
"except Exception:" is rarely what you want IMO. It also catches SyntaxError, which is almost always a design error -- one you'd typically prefer would halt the system.

Unfortunately there's no common parent to EnvironmentError/SystemError/RuntimeError/etc that excludes SyntaxError.

Re:Rust for Python Programmers by mixmastamyk on Wednesday May 27, 2015 @02:32PM (#9613410)
I can't seem to repro that, SyntaxError seems to happen before the code runs the first time. (2.7 Ubuntu)
Re:Rust for Python Programmers by wyldfire on Wednesday May 27, 2015 @04:15PM (#9614010)
SyntaxError can happen as a consequence of loading a module (hitting an import statement, etc). But for a simpler example, replace SyntaxError with NameError and it's still almost always a design error that you probably have no sane way to handle in an exception handler (other than to mask the problem).

Python's a very dynamic language and so of course you could come up with examples to the contrary (ones where the user input could trigger SyntaxError or NameError).

Re:Rust for Python Programmers by techdragon on Thursday May 28, 2015 @01:54AM (#9616273)
But the only universally good reason I know of where you should be wrapping imports in try except is 2/3 compatibility or other module/library import fallback. For these you need to be catching syntaxerror and other system errors.