nac3/examples/exception.py

39 lines
806 B
Python
Raw Normal View History

2020-06-30 17:25:44 +08:00
from artiq.experiment import *
from artiq.language.core import TerminationRequested
2020-06-30 17:25:44 +08:00
class ExceptionDemo(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("led0")
def foo(self):
print("raise error")
raise Exception
def termination(self):
raise TerminationRequested
@rpc
def remote(self):
raise Exception
2020-06-30 17:25:44 +08:00
@kernel
def run(self):
self.core.reset()
try:
try:
self.foo()
2020-06-30 17:25:44 +08:00
except ValueError as e:
print("should not trigger this")
2020-06-30 17:25:44 +08:00
except:
print("catch all")
try:
self.remote()
except:
print("Error!")
print("Uncaught error at last")
self.termination()
2020-06-30 17:25:44 +08:00