[英]Atlassian.NET SDK Async Methods don't throw Exceptions
編輯:
private void button1_Click(object sender, EventArgs e) {
string summary = "TestSummary";
string description = "TestDescription";
string type = "Task";
string projectKey = "TST";
string priority = "p - 3";
var issueCreated = createIssueWrapper(summary, description, type, priority, projectKey).Result;
}
public async Task <string> createIssueWrapper(string summary, string description, string type, string priority, string projectKey) {
string returnVal = "";
returnVal = await createIssue(summary, description, type, priority, projectKey);
return returnVal;
}
public async Task <string> createIssue(string summary, string description, string type, string priority, string projectKey) {
string returnVal = "";
try {
var issue = jira.CreateIssue(projectKey);
issue.Type = type;
issue.Priority = priority;
issue.Summary = summary;
issue.Description = description;
var jiraIssue = await issue.SaveChangesAsync();
if (jiraIssue != null) {
returnVal = jiraIssue.Key.ToString();
}
}
catch (Exception ex) {
returnVal = "There was a problem creating the issue. Please try again.";
}
return returnVal;
}
我一直試圖弄清楚為什么Atlassian.NET Jira異步方法沒有返回像常規(非異步)方法那樣的異常。
例如,我調用一個異步方法createIssue
創建一個新的Jira問題,如下所示:
string summary = "TestIssue";
string description = "TestDescription";
string type = "Task";
string projectKey = "TST";
string priority = "p - 3";
Task<string> created = createIssue(summary, description, type, priority, projectKey);
這是異步方法:
public async Task<string> createIssue(string summary, string description, string type, string priority, string projectKey)
{
string key = "";
try
{
var issue = jira.CreateIssue(projectKey);
issue.Type = type;
issue.Priority = priority;
issue.Summary = summary;
issue.Description = description;
var jiraIssue = await issue.SaveChangesAsync();
if (jiraIssue != null)
{
key = jiraIssue.Key.ToString();
}
}
catch (Exception ex)
{
}
return key;
}
我在await issue.SaveChangesAsync()
行上添加了一個斷點,並跨過它。 沒有引發異常,因此代碼繼續等待調用完成。 什么都沒有告訴我有問題。
所以我將createIssue
方法轉換為非異步方法:
var issue = jira.CreateIssue(projectKey);
issue.Type = type;
issue.Priority = priority;
issue.Summary = summary;
issue.Description = description;
issue.SaveChanges();
在這里,我得到一個異常,告訴我實際的問題:
{找不到類型為'Atlassian.Jira.IssuePriority'的名稱為'p-3'的ID為id的實體。可用:[10000:p-3,10001:N / A,4:p-4,3: p-2,2:p-1,1:p-0]“}
是否可以在Async方法中捕獲這些類型的異常? 我需要創建處理程序還是做其他事情?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.