我的ajax调用看起来像这样
$.ajax({ //actually approve or reject the promotion
url: url,
type: "POST",
data: '{'+data.PromotionId+','+data.UserId+','+data.ReasonText+'}',
dataType: "json",
//contentType: "application/json; charset=utf-8",
success: function (data) {
if (indicator == 'A') {
alert('Promotion approved successfully!');
}
else {
alert('Promotion rejected successfully.');
}
var homelink = '<%: Url.Action("Index","Home") %>';
window.location.href = (homelink);
returndata = data;
},
error: function (xhRequest, ErrorText, thrownError) {
alert("Failed to process promotion correctly, please try again");
console.log('xhRequest: ' + xhRequest + "\n");
console.log('ErrorText: ' + ErrorText + "\n");
console.log('thrownError: ' + …Run Code Online (Sandbox Code Playgroud) 以下代码应在理想情况下执行标量sql命令:
public object AsScalar()
{
SqlCommand cmd = CreateSqlCommand();
try
{
cmd.Connection.Open();
return cmd.ExecuteScalar();
}
catch (Exception exc)
{
log.Error("Exception caught for command: "+_sql, exc);
}
finally
{
Done(cmd);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我从Visual Studio 2010收到以下错误:
not all code paths return a value
Run Code Online (Sandbox Code Playgroud)
我认为在try-catch-finally中它总是会执行finally语句,无论是否捕获到异常,但似乎并非如此.
为什么在try-finally工作没有问题时添加catch子句会导致此错误?