Here I am again for my weekly Sunday night help. Sigh. How can I pass my error message into my exception? Thanks.

Let me know if you need to see more of the code.

/* Create an error message that is passed to the Exception class constructor for the Message property 
         * when a book does not meet the price-to-pages ratio. */
        public void displayErrorMessage()
        {
            string msg = "Ratio for " + Title + " is invalid. Price is " + Price + " for " + NumPages + " pages.";
        }


    }  //End Book Class
 
    /*Create a BookException class with a constructor that requires three (3) arguments for each book: 
       * a string title, a double price, and an int number of pages. */
    public class BookException : Exception
    {
        string displayErrorMessage(msg);
        public BookException(string Title, double Price, double NumPages)
            : base (msg)
        {
        }
        public BookException()
        {
        }
    }  //End BookException Class

call

throw new BookException(Title, Price, Numpages);

declare

public class BookException : Exception
{
    public BookException(string Title, double Price, double NumPages)
            : base (String.Format("Ratio for {0} is invalid. Price is {1} for {2} pages.", Title, Price, Numpages))
    {
    }
}

Why not inherit from ApplicationException in stead of the more generic Exception: you exception is actually a very particular ApplicationException.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.