Catch multiple exceptions with one statement #21

Open
opened 2021-07-13 02:40:02 +08:00 by lriesebos · 1 comment
Collaborator

Currently it is not possible to catch multiple exceptions with one except statement. Not sure if this should be resolved in the current compiler too, but it would be pleasant to have this at least in NAC3.

The following program

from artiq.experiment import *

class ArtiqTestExperiment(EnvExperiment):

    def build(self):
        self.setattr_device('core')

    @kernel
    def run(self):
        try:
            self.core.reset()
        except (RTIOUnderflow, ValueError):
            pass

return this compile error:

repository/artiq_test.py:13:16-13:43: error: this expression must refer to an exception constructor
        except (RTIOUnderflow, ValueError):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Currently it is not possible to catch multiple exceptions with one `except` statement. Not sure if this should be resolved in the current compiler too, but it would be pleasant to have this at least in NAC3. The following program ```python from artiq.experiment import * class ArtiqTestExperiment(EnvExperiment): def build(self): self.setattr_device('core') @kernel def run(self): try: self.core.reset() except (RTIOUnderflow, ValueError): pass ``` return this compile error: ``` repository/artiq_test.py:13:16-13:43: error: this expression must refer to an exception constructor except (RTIOUnderflow, ValueError): ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
Collaborator

Yes, this should not be too hard. I think we can also resolve this in the current compiler too if needed, I can look into it later when I have time.

Yes, this should not be too hard. I think we can also resolve this in the current compiler too if needed, I can look into it later when I have time.
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3-spec#21
No description provided.