Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Q# runtime exceptions are not raised as Python exceptions #556

Open
tcNickolas opened this issue Dec 22, 2021 · 1 comment · May be fixed by #560
Open

Q# runtime exceptions are not raised as Python exceptions #556

tcNickolas opened this issue Dec 22, 2021 · 1 comment · May be fixed by #560
Assignees
Labels
Area-Python Issue relates to the Python client for the IQ# kernel. Kind-Enhancement New feature or request

Comments

@tcNickolas
Copy link
Member

Describe the bug
Python host code doesn't receive runtime exceptions thrown by Q# code it calls.

To Reproduce
Steps to reproduce the behavior:
Q# code:

namespace Quantum.CircuitPuzzle {
    operation ThrowEx() : Int {
        fail "Throwing exception";
    }
}

Python host code:

import qsharp
from Quantum.CircuitPuzzle import ThrowEx

try:
    ThrowEx.simulate()
    print("Didn't catch exception")
except Exception:
    print("Caught exception")

Expected behavior
Python catching exception and printing "Caught exception".

System information

  • OS: Windows 11
  • dotnet iqsharp --version = 0.19.2109165653
@cgranade
Copy link
Contributor

cgranade commented Jan 7, 2022

Thanks for raising this, @tcNickolas! It shouldn't be too difficult to add an input handler to make sure that Q# failures are correctly propagated as Python exceptions; ideally, we would want to do so with compiler errors as well (#467).

@cgranade cgranade self-assigned this Jan 7, 2022
@cgranade cgranade added Area-Python Issue relates to the Python client for the IQ# kernel. Kind-Enhancement New feature or request labels Jan 7, 2022
cgranade added a commit that referenced this issue Jan 7, 2022
@cgranade cgranade linked a pull request Jan 7, 2022 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-Python Issue relates to the Python client for the IQ# kernel. Kind-Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants