Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:29:27+00:00 2026-05-26T02:29:27+00:00

I am trying to have an ApplicationException exception which will show ONLY a message

  • 0

I am trying to have an ApplicationException exception which will show ONLY a message when input is not a number. Here is what I have right now:

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."
        );  
    }
}

Whole Program.cs after edit which works. The problem was that ApplicationException part was displaying whole printout of the exception, now instead of doing that, it shows only message part. As usually it’s something simple. 🙂

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."
                )   
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:29:27+00:00Added an answer on May 26, 2026 at 2:29 am

    Exceptions don’t show anything. That’s up to the code that catches them.

    Also, you should not use ApplicationException. Either use Exception, or use something more specific like FormatException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a comment input field that will show the submit button
Trying to have a page which will not take everything from layouts/application.html.erb, Is it
I have trying this for some time now but I am not able to
Afternoon, I am trying have an HTML file containing a frameset which contains two
Trying to have the label.error to show under the select element. I keep trying
Im trying to have multiple instances of a tabbed content box, only for some
Trying to have a AJAX action link which when clicked, should do a HttpGet
Trying to have a custom function where the text is in the input on
Trying to have a user input their name, copy that variable to a file,
Am trying to have an image visually echo through from intro page to homepage~which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.