ExceptionオブジェクトのInnerExceptionプロパティがnullであるかどうかを確認するにはどうすればよいですか?
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Error.aspx.cs" Inherits="XEx21HandleErrors.Error" %>
<asp:Content ContentPlaceHolderID="mainPlaceholder" runat="server">
<h1 class="text-danger">An error has occurred</h1>
<div class="alert alert-danger">
<p><asp:Label ID="lblError" runat="server"></asp:Label></p>
</div>
<asp:Button ID="btnReturn" runat="server" Text="Return to Order Page"
PostBackUrl="~/Order.aspx" CssClass="btn btn-danger" />
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace XEx21HandleErrors
{
public partial class Error : System.Web.UI.Page
{
private Exception ex;
protected void Page_Load()
{
if (ex.InnerException == null)
{
lblError.Text = ex.Message;
}
else ex.InnerException;
}
}
}
こんにちはすべて、
私は、ExceptionオブジェクトのInnerExceptionプロパティがnullであるかどうかを確認したいアプリケーションに取り組んでいます。表示されている場合は、ExceptionオブジェクトのMessageプロパティを表示します。 それ以外の場合は、InnerExceptionプロパティによって返されたExceptionオブジェクトのMessageプロパティを表示します。ここまで私がこれまで持っていたことがあります。私は尋ねるために、私はPage_Loadイベントハンドラを作成しましたが、私はelse部分で立ち往生しています。誰か助けてくれますか?誰かがこの例外エラーメッセージがどこに表示されるかを正確に知りたい場合に備えて、エラーページも含めました。