Advertisement
touhid_xml

Try Catch C#

Oct 17th, 2013
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace try_Catch
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             try
  22.             {
  23.                 String[] city = { "Dhaka", "Dinajpur", "Rangpur" }; // here key 0 for Dhaka, 1 fro DInajpur, 2 for Rangpur
  24.  
  25.                 MessageBox.Show(city[3]); // Should get error for key 3 which is not exist in array
  26.             }
  27.  
  28.             catch
  29.             {
  30.                 MessageBox.Show("There is an Error");
  31.  
  32.             }
  33.  
  34.             //code by Touhid
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement