Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
Exception handling in asp.net c# with example
5438 Views
Note 
It has try block ,Catch block ,finally(optional) block
  1. type all the code inside try block if any error occured the catch block code will run.Handle the error in catch block occording to your need.
  2. If no error in try block the catch block will not run.
  3. finally block codes will run after run the try block code .codes inside the finally block must run,not like catch block.
  4. codes should be run ,if you type the codes inside the finally block.
Syntax
	function()
	       {
	           try
	           {
	              //statements
	           }
	           catch
	           {
	               //statements
	           }
	           finally
	           {
	               //statements
	           }
	       }
Example
	public DataSet dalReportSear(boAddCds date)
	       {
	           try
	           {
	               string datestring = date.dt.Date.ToString("yyyy-MM-dd");
	               conn.Open();
	               SqlCommand cmd = new SqlCommand("select * from cdMove where issuedOn='" + datestring + "'", conn);
	               SqlDataAdapter da = new SqlDataAdapter(cmd);
	               DataSet ds = new DataSet();
	               da.Fill(ds);
	               return ds;
	           }
	           catch (Exception ex)
	           {
	               throw ex;
	           }
	           finally
	           {
	               conn.Close();
	           }
	       }
Best Lessons of "Asp.net/Ado.net/C#.net(Dotnet)"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details