Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Show only Message from ApplicationException
- static void getBookInfo(Book book)
- {
- bool isNumeric;
- float number;
- string numberInput;
- Console.Write("Enter Book Title: ");
- book.Title = Console.ReadLine();
- Console.Write("Enter Author's First Name: ");
- book.AuthorFirstName = Console.ReadLine();
- Console.Write("Enter Author's Last Name: ");
- book.AuthorLastName = Console.ReadLine();
- Console.Write("Enter Book Price: $");
- numberInput = Console.ReadLine();
- isNumeric = float.TryParse(numberInput, out number);
- if (isNumeric)
- book.Price = number;
- else
- {
- throw new ApplicationException
- (
- "This is not a number!n" +
- "Please try again."
- );
- }
- }
- using System;
- namespace Lab_6
- {
- class Program
- {
- static void Main(string[] args)
- {
- Address address = new Address();
- address.StreetNumber = "800";
- address.StreetName = "East 96th Street";
- address.City = "Indianapolis";
- address.State = "IN";
- address.ZipCode = "46240";
- Book book = new Book();
- try
- {
- getBookInfo(book);
- book.PublisherAddress = address;
- book.PublisherName = "Sams Publishing";
- Console.WriteLine("----Book----");
- book.display();
- }
- catch (NegativeInputException ex)
- {
- Console.WriteLine(ex.Message);
- return;
- }
- catch (ApplicationException ex)
- {
- Console.WriteLine(ex.Message); // I had to change so I have only this,
- // instead of whole printout.
- return;
- }
- }
- static void getBookInfo(Book book)
- {
- bool isNumeric;
- float number;
- string numberInput;
- Console.Write("Enter Book Title: ");
- book.Title = Console.ReadLine();
- Console.Write("Enter Author's First Name: ")
- book.AuthorFirstName = Console.ReadLine();
- Console.Write("Enter Author's Last Name: ");
- book.AuthorLastName = Console.ReadLine();
- Console.Write("Enter Book Price: $");
- numberInput = Console.ReadLine();
- isNumeric = float.TryParse(numberInput, out number);
- if (isNumeric)
- book.Price = number;
- else
- {
- throw new ApplicationException
- (
- "This is not a number!n" +
- "Please try again."
- )
- }
- }
- }
- }
- if (isNumeric)
- {
- book.Price = number;
- }
- else
- {
- MessageBox.Show("This is not a number!n" + "Please try again.");
- }
- try
- {
- getBookInfo(...)
- }
- catch (ApplicationException exception)
- {
- MessageBox.Show(exception.Message);
- }
- try
- {
- Book myBookParameter = .....;
- getBookInfo(myBookParameter);
- }
- catch(ApplicationException x)
- {
- MessageBox.Show(x.Message);
- }
Add Comment
Please, Sign In to add comment