Net-informations.com
SiteMap  | About    

ASP.NET Exceptions

Exceptions are the occurrence of some conditions that changes the normal flow of execution . Exceptions are occurred in situations like your program run out of the memory , file does not exist in the given path , network connections are dropped etc.

All exceptions in the Common Language Runtime are derived from a single base class , also you can create your own custom Exception classes.

You can handle Exceptions using Try..Catch..Finally statement .The code in the finally block will execute even if there is no Exceptions occurred.

vb.net
  Try
	statements
  Catch [Exception [As Type]]
	statements
  Finally

statements

C#
  try
  {
	statements
  }
  Catch (exception type)
  {
	statements
  }
  finally
  {
	statements

}

The following ASP.NET program trying to divide a number by zero.

Default.aspx

  

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
		<br />
		<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
		<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
		<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
Default.aspx.cs
Default.aspx.vb






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.