- CustomExceptions.aspx (nuestra página aspx)
<body>- CustomExceptions.aspx.cs (nuestro archivo de code behind)
<form id="form1" runat="server">
<div>
<asp:Label ID="lblException"
runat="server" Text="" />
</div>
</form>
</body>
using System;
using System.Web.UI;
public class MyCustomException : Exception {
public MyCustomException(string message) : base(message) { }
}
public partial class TestCustomExceptions : Page {
public void Page_Load(object sender, EventArgs e) {
try {
if (1 == 1) {
throw new MyCustomException("Testing Custom Exceptions.-");
}
} catch (MyCustomException exc) {
Trace.Write(exc.Message);
lblException.Text = exc.Message;
}
}
}
No hay comentarios.:
Publicar un comentario