[Django]-Handling of view syntax error vs exceptions in django

5👍

Don’t try to make Django return a nice response in the case of a syntax error. That will be difficult, and will involve having code of your own just for this case, and that code itself will need to be error-free, etc.

Instead, put that effort into an automated test suite that will make it easy to find those errors before you deploy your code.

2👍

Syntax errors can be detected trivially as you don’t need to run the code but only to import it.

There’s no reason you should try to catch them, just fix them.

0👍

You can catch syntax (And Indentation) errors out of your code.
Look here for more info:
How to catch IndentationError

0👍

Syntax errors are not run time errors, they occur at compile time. As far as I know, you can’t catch them with a try/except block.

Leave a comment