|
3 | 3 |
|
4 | 4 | using System; |
5 | 5 | using System.Collections.Immutable; |
| 6 | +using System.Reflection; |
6 | 7 | using System.Threading.Tasks; |
7 | 8 | using Microsoft.Azure.Quantum; |
8 | 9 | using Microsoft.Azure.Quantum.Exceptions; |
@@ -204,23 +205,53 @@ private static async Task<int> SubmitQir( |
204 | 205 | /// <returns>The exit code.</returns> |
205 | 206 | private static async Task<int> DisplayJobOrError(AzureSettings settings, Task<IQuantumMachineJob> job) |
206 | 207 | { |
| 208 | + void DisplayAzureQuantumException(AzureQuantumException ex) => |
| 209 | + DisplayError( |
| 210 | + "Something went wrong when submitting the program to the Azure Quantum service.", |
| 211 | + ex.Message); |
| 212 | + |
| 213 | + void DisplayQuantumProcessorTranslationException(QuantumProcessorTranslationException ex) => |
| 214 | + DisplayError( |
| 215 | + "Something went wrong when performing translation to the intermediate representation used by the target quantum machine.", |
| 216 | + ex.Message); |
| 217 | + |
| 218 | + bool HandleTargetInvocationException(TargetInvocationException ex) |
| 219 | + { |
| 220 | + if (ex.InnerException is AzureQuantumException azureQuantumEx) |
| 221 | + { |
| 222 | + DisplayAzureQuantumException(azureQuantumEx); |
| 223 | + return true; |
| 224 | + } |
| 225 | + else if (ex.InnerException is QuantumProcessorTranslationException quantumProcessorTranslationEx) |
| 226 | + { |
| 227 | + DisplayQuantumProcessorTranslationException(quantumProcessorTranslationEx); |
| 228 | + return true; |
| 229 | + } |
| 230 | + |
| 231 | + return false; |
| 232 | + } |
| 233 | + |
207 | 234 | try |
208 | 235 | { |
209 | 236 | DisplayJob(await job, settings.Output); |
210 | 237 | return 0; |
211 | 238 | } |
212 | 239 | catch (AzureQuantumException ex) |
213 | 240 | { |
214 | | - DisplayError( |
215 | | - "Something went wrong when submitting the program to the Azure Quantum service.", |
216 | | - ex.Message); |
| 241 | + DisplayAzureQuantumException(ex); |
217 | 242 | return 1; |
218 | 243 | } |
219 | 244 | catch (QuantumProcessorTranslationException ex) |
220 | 245 | { |
221 | | - DisplayError( |
222 | | - "Something went wrong when performing translation to the intermediate representation used by the target quantum machine.", |
223 | | - ex.Message); |
| 246 | + DisplayQuantumProcessorTranslationException(ex); |
| 247 | + return 1; |
| 248 | + } |
| 249 | + catch (TargetInvocationException ex) |
| 250 | + { |
| 251 | + if (!HandleTargetInvocationException(ex)) |
| 252 | + { |
| 253 | + throw; |
| 254 | + } |
224 | 255 | return 1; |
225 | 256 | } |
226 | 257 | } |
|
0 commit comments