certain magics swallow their exceptions, %cd in particular. We made that decision to make them more human-friendly, since magics were originally conceived really as a pure human-driven convenience while working interactively, not as a library/programming construct.
In general, the magic system does *not* swallow all exceptions, though, so you could add your own versions of the ones you need with different behavior.
Not an ideal answer, but at least the system doesn't intrinsically prevent what you're looking for (which I was afraid we might, so I actually went looking a bit).
On Tue, Jan 6, 2015 at 8:42 AM, Catherine Devlin <[hidden email]> wrote:
I really enjoy being able to build informal IPython scripts that include line magics. Maybe too much.
When I do so, is there a way to trap errors thrown by line magics? This doesn't work as I had hoped:
[Errno 2] No such file or directory: 'directory_that_does_not_exist'