python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
69 stars 41 forks source link

microscope specific exceptions #134

Closed carandraug closed 4 years ago

carandraug commented 4 years ago

I think it would be nice to have specific exceptions for microscope. I'm constantly thinking it would be nice to have a specific exception class for cases but end up either raising a general Exception or RuntimeException because it's too much trouble thinking about the exception hierarchy we should have.

It's easy to fall in the trap of having too many exception types, one for each case. It's hard to get the balance right but I guess the only way to find out is to start doing it and adjusting over time. I propose we create a base MicroscopeException and start from there and trim down later. We can recommend users to only catch the base microscope exception in order to not worry about keeping backwards compatible.

Some of the exceptions I would like are:

carandraug commented 4 years ago

I've looked at all the exceptions currently being raised in microscope and here's what I've found.

First the easy ones that I have already handled with builtin exceptions:

The others are a bit more complex and I think some can be grouped:

Taken this into account, here's the exceptions I propose:

MicroscopeError
  +-- DeviceError
  |    +-- IncompatibleStateError
  |    |    +-- DisabledDeviceError
  |    +-- InitialiseError
  |    +-- possibly to further subclass later (see below)
  +-- LibraryLoadError
carandraug commented 4 years ago

Now done.