Catching exceptions


I have started working on a PCell script in Python and I need to catch exceptions, but it seems I cannot for KLayout catches them somehow. I could not find any documentation on this. Does anyone know how to get the following code to work:

  a = a
  print("You cannot do that!")

When I run this, KLayout catches the exception, so I never get to my except-statement.


  • When I put that into the macro IDE and run it, it exactly catches the exception. You need to turn off the debugger in order to stop it from reporting the original error, but I assume that is not what you want to know.

    So you're not giving the full details here. I guess you want to raise an exception inside PCell code and catch it outside. You can't do that. PCell evaluation and outside code are different domains. Exceptions don't cross them.


  • This is related to the other question that I asked (and got answered) and I think I understand now. Thanks. So I just need to turn off the debugger for my code to do what I want. Actually, I am fine with catching the exception in the PCell code. I need to do exec() with some possibly erroneous code (I know exec has enough rope to hang myself, but I think it is worth that for my application).

    Thanks for your reply.

Sign In or Register to comment.