-2

is it possible to catch the

IndentationError

in python? is it possible to do this with try/except? using other methods? if not why

  • 1
    `Try/except` *where*? Around every piece of indentation? The best way of avoiding `indentationError` is to use four spaces, and only four spaces. Never *ever* use tabs. – SiHa May 16 '22 at 18:59
  • 3
    Errors like `IndentationError` or `SyntaxError` will break execution of your program before it's possible to do any exception handling. You need correct syntax/indentation for the interpreter to know how to interpret your `try/except` in the first place. – Samwise May 16 '22 at 19:00
  • Welcome to Stack Overflow! Please take the [tour]. Adding to the other comments, the only way you'd be able to catch an `IndentationError` or `SyntaxError` is if you're compiling code at runtime, like importing another Python module or using [`compile()`](https://docs.python.org/3/library/functions.html#compile). Is that what you're doing? You can [edit] to clarify if needed. Please add an example if you do. For more tips, see [ask]. – wjandrea May 16 '22 at 19:21

0 Answers0