How am I supposed to catch a custom exception when I cannot import `pyvisa-py` due to the minus sign in the package name?
See original GitHub issueDear all,
sometimes I need to deal with exceptions which are raised by pyvisa-py
, for example pyvisa-py.protocols.rpc.RPCError
.
I cannot catch this specific exception, since I need to import it, which is not possible since the package name contains a minus sign (not allowed in Python module/package names).
Maybe I am missing something obvious here, but I have no idea how this package should be used externally.
I could not find anything related in the visa
or pyvisa
package…
Thanks, Tom
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to catch a custom exception not defined by me in python
but if I try do modify my except statement from except Exception as e to except DoStuffInsufficientMemoryException , I will get the error...
Read more >How to Define your own Custom Exception Class ... - YouTube
You can define your own custom exception type, by inheriting from a built-in exception class and modifying it as neededYou can raise your ......
Read more >Python Exception Handling: ImportError and ... - Airbrake Blog
A look into the ImportError and ModuleNotFoundError in Python, with code showing how to deal with failed imports in Python 2.7 and 3.6....
Read more >PyMeasure Documentation
PyMeasure makes scientific measurements easy to set up and run. The package contains a repository of instrument.
Read more >qcodes.instrument_drivers.Keysight package
This method can be overridden to have a custom sweep behaviour. ... from qcodes.parameters import Parameter >>> p = Parameter("p", set_cmd=None, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s hard to reproduce… it happens during very long (>50 hours) data takings from time to time. I’ll try to get some useful information.
OK, I’ll go with
importlib
then. Still wondering why an invalid package names chosen initially…Indeed
PyVisaLibrary.open
should catch errors when creating sessions. Sessions should raise errors that makes it easy to provide the right kind of error messages. However we should catch all exceptionsPyVisaLibrary.open
and not-only the types we expect.We also have to make sure that we preserve enough information to debug the error. If we cannot propagate a meaningful error message, we should at the very least log them.
I do not think we need to convert the
rpc.RPCError
to a bareException
, using anexcept Exception
clause will catch everything we can be interested in.