i didn't understand from the question if the user needs to enter data or not
can some one verify it with me
tried to follow the instructions,
and thats my 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 BookExceptionDemoGUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Book book1=new Book("Microsoft visual C#", "Joyce Farrell",40,120);
Book book2=new Book("ASP.Net","Joyce Farrell",130,120);
double price_Page =book2.price/book2.pages;
try
{
if (price_Page > 10)
{
throw new BookException(); //Throws the BookException
}
}
catch (Exception ex)
{
label1.Text = (ex.ToString());
}
label1.Text ="The ratio is invalid";
}
}
public class BookException : Exception
{
private static string msg = "The ratio is invalid.";
public BookException() : base(msg)
{
}
}
public class Book
{
public string title;
public string author;
public double price;
public int pages;
public Book(string tit, string au, double pr, int pag)
{
this.title = tit;
author = au;
pages = pag;
price = pr;
}
}
}