Replies: 4 comments 9 replies
-
This is what I am currently using for exceptions, it appears to be limited to RuntimeError and a message |
Beta Was this translation helpful? Give feedback.
-
See if this will be helpful. https://stackoverflow.com/questions/2261858/boostpython-export-custom-exception |
Beta Was this translation helpful? Give feedback.
-
Okay, great idea, seems very useful! |
Beta Was this translation helpful? Give feedback.
-
I was able to get the sample from stack overflow working (the one by David Faure towards the end). I don’t know if I like it as it’s kind of a monkey patch. The sample attaches an object ‘cause’, which I renamed ctx, short for context to the built-in exception. ctx has properties err.ctx.fullmessage
err.ctx.message
err.ctx.code example: from pyrx_imp import Ap, Db, Ed, Ge, Gi, Gs, Rx
def PyRxCmd_edoit1():
try:
db = Db.curDb()
text = Db.Text()
text_id = db.addToModelspace(text)
Db.Text(text_id, Db.OpenMode.kForRead)
except Db.ErrorStatusException as err:
match err.ctx.code:
case Db.ErrorStatus.eWasOpenForWrite:
print("caught eWasOpenForWrite")
case Db.ErrorStatus.eOnLockedLayer:
print("caught eOnLockedLayer")
case _:
print("caught {}".format(err.ctx.code))
except Exception as err:
print(err)
def PyRxCmd_edoit2():
try:
db = Db.curDb()
text = Db.Text()
text_id = db.addToModelspace(text)
Db.Text(text_id, Db.OpenMode.kForRead)
except Db.ErrorStatusException as err:
match err.ctx.message:
case 'eWasOpenForWrite':
print("caught eWasOpenForWrite")
case 'eOnLockedLayer':
print("caught eOnLockedLayer")
case _:
print("caught {}".format(err.ctx.code))
except Exception as err:
print(err)
def PyRxCmd_doit1():
try:
db = Db.curDb()
text = Db.Text()
text_id = db.addToModelspace(text)
Db.Text(text_id, Db.OpenMode.kForRead)
except Db.ErrorStatusException as err:
print(1,err.ctx.fullmessage)
except Exception as err:
print(4,err)
def PyRxCmd_doit4():
try:
db = Db.curDb()
text = Db.Text()
text_id = db.addToModelspace(text)
Db.Text(text_id, Db.OpenMode.kForRead)
except Exception as err:
print(4,err) |
Beta Was this translation helpful? Give feedback.
-
To make working with C++ exceptions easier I added tools to translate general C++ exceptions (
RuntimeError
) to specific types. You can see the implementation here.Usage looks like this:
I wonder if I should stick to this path or if you have a better idea..? Maybe you want to implement something similar in C++?
Beta Was this translation helpful? Give feedback.
All reactions