title: Try catch statements with window forms application
body: <p>My goal is to throw a NegativeBalanceException if there is an attempt to take the balance below zero. Just like if this was a real bank account. I had if and else statements, but butchered them up and am trying to learn try, catch, and throw statements (was reading on finally as well but I don't think that applies here). Anyway, I set up where a catch statement works if I just hit the deposit button without typing anything. But, I don't understand where it is wanting me to implement it in for taking it below zero. Is it in my deposit method? Or is it in the actual btn_deposit? Also, what is the purpose of using try catch statements over if else statements? I am new to programming and am just trying to learn. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication2
  {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
      public class BankAccount
      {
          decimal amount = 300.00m;
          // Declare Delegate Type Object
          public delegate void BankDelegate(decimal oldBalance, decimal newBalance);
          // Create Delegate Type Events 
          public event BankDelegate OnDeposit;
          public event BankDelegate OnWithdraw;
  
          public void Deposit(decimal a)
          {
              {
                  if (a &gt; 0)
                  {
                  OnDeposit(this.amount, this.amount + a);
                  this.amount += a;
                  }
                  else
                  {
                      MessageBox.Show("No!");
                  }
              }
          }
          public void Withdraw(decimal a)
          {
              // Fire OnWithdraw Event and pass old and new balance amount
              OnWithdraw(this.amount, this.amount - a);
              this.amount -= a;
          }
      }
      // Declare BankAccount class variable 
      BankAccount account = null;
      private void Form1_Load(object sender, EventArgs e)
      {
          account = new BankAccount();
          // Attach Event Handlers with Events     
          account.OnDeposit += new BankAccount.BankDelegate(account_OnDeposit);
          account.OnWithdraw += new BankAccount.BankDelegate(account_OnWithdraw);
      }
      private void btnDeposit_Click(object sender, EventArgs e)
      {
          try
          {
                  account.Deposit(Convert.ToDecimal(textBox1.Text));
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
      private void btnWIthdraw_Click(object sender, EventArgs e)
      {
          account.Withdraw(Convert.ToDecimal(textBox1.Text));
      }
      void account_OnDeposit(decimal oldBalance, decimal newBalance)
      {
          label4.Text = oldBalance.ToString();
          label5.Text = newBalance.ToString();
      }
      void account_OnWithdraw(decimal oldBalance, decimal newBalance)
      {
          label4.Text = oldBalance.ToString();
          label5.Text = newBalance.ToString();
      }
  }
  </code></pre>
  
  <p>}</p>