question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Dear 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:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tamasgalcommented, May 16, 2018

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…

0reactions
MatthieuDartiailhcommented, Jan 11, 2019

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 exceptions PyVisaLibrary.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 bare Exception, using an except Exception clause will catch everything we can be interested in.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found