Advertisement
AalborgHTX

Try Catch

Jan 29th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication3
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             try
  23.             {
  24.                 int tal1 = int.Parse(textBox1.Text);
  25.                 int tal2 = int.Parse(textBox2.Text);
  26.  
  27.                 int sum = tal1 / tal2;
  28.                 label1.Text = sum.ToString();
  29.             }
  30.  
  31.             catch (System.FormatException)
  32.             {
  33.                 MessageBox.Show("formatexception");
  34.             }
  35.  
  36.             catch (System.DivideByZeroException)
  37.             {
  38.                 MessageBox.Show("dividezeo");
  39.             }
  40.            
  41.             catch (System.Exception)
  42.             {
  43.                 MessageBox.Show("generel exception");
  44.             }
  45.  
  46.             finally
  47.             {
  48.                 MessageBox.Show("finally");
  49.             }
  50.          
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement