【发布时间】:2013-02-10 11:00:36
【问题描述】:
我有时会在实时应用程序中遇到错误。
堆栈跟踪:
在 Tool.User_RequestSender.Page_Load(Object sender, EventArgs e) 中 d:\Site\Tool\User\RequestSender.aspx.cs:第 72 行 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象 o,对象 t,EventArgs e) 在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者, EventArgs e) 在 System.Web.UI.Control.OnLoad(EventArgs e) 在 System.Web.UI.Control.LoadRecursive() 在 System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)
我一次又一次地尝试在我的机器上运行代码,但没有得到同样的错误。
即使我是实时代码,我也会偶尔遇到这个问题。
RequestSender.aspx.cs 中的Page_Load 代码:
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
this.LoadRequest();
}
}
catch (CustomException ex)
{
this.ShowMessage(ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
LoadRequest()如下:
private void LoadRequest()
{
Credential credential;
if (
!string.IsNullOrEmpty(Request["typeOfrequest"]) &&
!string.IsNullOrEmpty(Request["empUserId"]) &&
!string.IsNullOrEmpty(Request["applicationId"])
)
{
// Get details of credentials
credential = (new RequestManager()).GetCredential(this.EmpUserId, this.ApplicationId, (int)this.TypeOfrequest);
this.applicaionRequest = new Request
{
RequestType = this.TypeOfrequest,
RequestStatus = Enumerations.RequestStatus.Sent,
Application = credential.Application,
EmpUserId = credential.EmpUserId,
EmployeeId = credential.EmployeeId,
Username = credential.Username,
SenderAddress = Security.CurrentUser.Details.EmailAddress,
ReceiverAddress = (new Datastore.RequestStore()).GetReceiverAddress((int)this.TypeOfrequest, this.ApplicationId),
AddedBy = Security.CurrentUser.Details.UserId
};
ucSendRequest.ApplicationRequest = applicaionRequest;
}
else
{
Response.Write("Invalid request!");
Response.End();
}
}
}
【问题讨论】:
-
您拥有
catch(Exception ex) { throw ex; }的事实掩盖了最初的原因。摆脱那个 catch 块,你会更好地了解发生了什么。 -
什么是 ucSendRequest?
-
Exaclty...但我无法在我的机器上出错...即使我删除了 try catch 我也不会在我的机器上再次收到任何错误或问题...
-
@mihirj:是用户控制
-
捕获异常然后发出“throw ex”会替换堆栈跟踪,这意味着您找到异常实际来自何处的机会较小。如果您需要重新抛出您已捕获的异常,请在 catch 块内单独使用“throw”。如果你的 catch 块中除了 throw 之外什么都没有,那么你一开始就不需要 catch 块。