Title:How to use Exception handling in asp.net using c#.net
Description:
To handle the exceptions we are provided two different blocks of code known as key,catch blocks which should be used as following
Description:
To handle the exceptions we are provided two different blocks of code known as key,catch blocks which should be used as following
Try
{
Statements which may cause you the exception
Statements which are related with the exception
}
catch(<exception><obj>
{
Statements that should execute when exception occurs(error message)
}
Once we enclose the code under try and catch blocks the execution of the programs will be as following
If all statements under try are executed successfully,the control jumps to the end of the catch block with out executing the catch blocks
If any of the statement under try executes an exception,the control from that hold the exception object or not,if they control hold abnormal termination occurs
using System Class trycatchdemo { static void main() { int x,y,z; try { console.write("Enter X value"); x=int.parse(console.ReadKey()); console.Write("enter y value"); y=int.parse(console.ReadKey()); z=x/y; console.Write("The result is" +z);); } catch (DivideByZeroException ex) { console.Write("Can not divide by zero"); } catch(FromatException ex1) { console.Write("Can not divide by char"); } catch(exception ex2) { console.Write("error occur"); } } } } }
No comments:
Post a Comment