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

  • Home
  • SEARCH
  • 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 4078278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:39:16+00:00 2026-05-20T17:39:16+00:00

Pretty new to C#, and I’d like to know how should I be using

  • 0

Pretty new to C#, and I’d like to know how should I be using exceptions? I mean, not a mechanics level, but at a good practice level.

I’ll use for example my calculator which tokenizes and the converts to RPN and solves problems given in RPN.

During the tokenizing step there’s various invalid inputs, say “7.7.8” or “^&##”, should I have separate exceptions for unknown symbols and invalid numbers? Is it wrong to say have a single exception and then a method in it containing the kind of error, to be given to the user?

I’ve really not been able to find much material on this kind of thing, so I thought I’d ask people with more experience than me.

—–Edit:

Thanks everyone for your awesome responses, I learned a ton today 🙂 about my question, and even more for that matter.

  • 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-20T17:39:17+00:00Added an answer on May 20, 2026 at 5:39 pm

    Think about your lexer from the perspective of preconditions and postconditions. Here are two ways to design a lexer :

    1. A lexer is a device which takes in a well-formed input string and outputs a lexical analysis. The input string is required to be well-formed; if it is not then the lexical analyzer fails with an exception.

    2. A lexer is a device which takes an input string and produces a lexical analysis. Lexical analysis includes identification of and analysis of error conditions.

    Do you know that the string you’re going to pass in is correct, and you want an exception in the exceptional circumstance that it is incorrect? Or do you not know that the string is correct, and you wish the lexer to determine that?

    In the former case, throw an exception. In the latter case, make the error analysis part of the output of the lexer.

    Basically what I’m saying is do not produce vexing exceptions. Vexing exceptions are extremely irritating. If the caller of your code is calling it to determine whether the string is correct then they don’t want that information in the form of an exception, they want it in the form of a data object that represents the error analysis. If the purpose of the code is to produce an error analysis then produce such an analysis as the normal operation of the method. Do not embed the analysis in an exception and make someone trap the exception in order to get it.

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

Sidebar

Related Questions

I am pretty new to php, but I am learning! I have a simple
I'm pretty new to my company (2 weeks) and we're starting a new platform
I'm a pretty new C# and .NET developer. I recently created an MMC snapin
I'm pretty new to the idea of recursion and this is actually my first
I am pretty new to VB.NET - and I'm struggling to convert the signature
I'm pretty new to JSF and the many many related technologies out there. I'm
I'm pretty new to regular expressions. I have a requirement to replace spaces in
I'm pretty new to the C++ build flow, and I'm thinking of switching to
I'm pretty new to the Spring Framework, I've been playing around with it and
I am pretty new to the Unity Application Block and am a little stuck

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.