Calling "if" statement on errors (TypeError, ValueError, SyntaxError...)

I’m creating an operating system within python.
I’ve created the init system, the workflows, the plans…
The only thing i need to do now is to make a valid shell
I want to integrate Bash and Python together, so I’d need a way to have an “if” statement for example:
text = input("PySH> ")
if input == SyntaxError:
# execute this
That’s my crude explanation of what my problem is

Here’s a nice introduction to Python exceptions:

2021-04-20_16-37-28

The line app in your run() function does nothing. It just evaluates the variable app into the string it contains and then does nothing with this string. It looks like you want to execute the contents of app as Python code, so you would need to do exec(app).

Hello 404oops,

maybe you are caught in syntax of “if” or of “while” ?
How about to try it with switch-case implementation (similiar like in C) ?
In youtube is video about this :

Hi @404oops ,

Your code seems not be executed in run function, and you just call os.system to exec your code on original system not you PyOS.
As @adang1345 said, you need define a function about how to parser your bash script and execute it. Then raise an Exception.
About if, my idea is:

try:
    run()
except Exception as e:
    if isinstance(e, TypeError):
        pass
    elif isinstance(e, ValueError):
        pass
    ...
    raise e

Or try it with switch-case like @monty1001 said.