Why is 'Unexpected indent' occuring in this Python code?
Question: The following is Python code that I typed:

    
    
    import builtins
    try:
        a = input("Enter name :- ")
        if (a=='Joey'):
            print("Yeah right ?!?")
              print("How come")
        else:
            print("No Problem")
    except IndentationError as i:
        print("Error : {0}".format(i))
    

Instead of handling the exception and printing the error message, I get an
**"Unexpected indent"** error message.

Why is this happening?

Thanks in advance.


Answer: You cannot catch syntax errors (including indentation errors) _in the code
that triggers the exception itself_.

The exception is thrown by the parser as it loads your file, not as it runs
the code. The code is never run because of the error.

You can only catch the exception from the 'outside', when loading the module
with `import` or when passing text to the `compile()` function, for example.

