Break on custom exception

Dec 8, 2012 at 7:07 PM

Hello,

I'm using Debug->Exceptions... dialog to select Python exceptions which breaks when exception is raised. Now I try to add new exception (my custom exception derived from Exception), but the application didn't break when my exception is raised. As a 'Type' I select Python Exceptions and as a 'Name' I use my custom exception class name. Is it even possible to add custom exception?

Thanks for the answer.

Coordinator
Dec 10, 2012 at 4:49 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Dec 10, 2012 at 4:49 PM

It's supposed to be possible, and we've done it in the past, but it looks like something may have broken (or is different).

I just tried it and it's not working properly in our latest version, so I'll create an issue and we'll look into it.

Coordinator
Jan 28, 2013 at 7:54 PM

Okay, I've tried again and it seems to be fine, but there are a few tricks.

First, the name that needs to be entered must be the full name as seen by Python, which is equivalent to ex_type.__module__ + '.' + ex_type.__name__

For example, if you define "class MyError(Exception): pass" in "Mod.py", you need to enter "Mod.MyError" in the Exception dialog.

The trick is that if you define the error in your startup script, the module name will be "__main__" and not the name of the file. This is because Python treats imported files differently from the start script.

I'll add these on the issue and we'll look at some ways to make it more flexible, but the feature does work, it just requires the name to match precisely (because we use getattr() to find the class and then issubclass() to compare it to the exception type).