ASP.Net/Language Basics/Catch Exception — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:53, 26 мая 2010
Use try catch to handle error (C#)
<source lang="csharp">
<script Language="c#" runat="server" >
void StructuredErrorHandling () { try { int [] array = new int[9]; for(int intCounter=0; intCounter <= 9; intCounter++) { array[intCounter] = intCounter; Response.Write("The value of the counter is:" + intCounter + "
"); } } // Handler for index out of range exception catch (IndexOutOfRangeException ex) { Response.Write("Error Occurred"+ "
" + ex.ToString() + "
"); } // Handler for generic exception catch (Exception e) { Response.Write("Generic Error Occurred" + "
"); } finally { Response.Write("The Page Execution is completed" + "
"); } }
</script> <%
StructuredErrorHandling(); Response.Write("Function call completed" + "
");
%>
</source>