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 7642435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:11:21+00:00 2026-05-31T09:11:21+00:00

I need to make a class Expr having public interface like this: class Expr{

  • 0

I need to make a class Expr having public interface like this:

class Expr{
    //...
public:
   Expr(const char*);
   int eval();           //Evaluates the expression and gives the result
   void print();
};

In the design, if user enters an invalid string to construct an Expr object like “123++233+23/45”, would it be right to construct the Object initially and notify the error when eval() is called on that object.

Or the error should be checked at that point itself and en exception be thrown, though that would lead to serious increase in runtime. And the user may write code furthur with assumption that Object is created and will discover the error at runtime only..

Such problems arise always in creating a class, is there a rather standard way to handle such errors made at user’s part????

  • 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-31T09:11:22+00:00Added an answer on May 31, 2026 at 9:11 am

    The only standard part about how you do this is thorough documentation.

    I prefer throwing the errors as early as possible, or using a factory for objects of this type – objects that require specific arguments to be initialized. If you use a factory, you can return a NULL or a nullptr or whatever.

    I don’t see the point in constructing the object and returning an error only when eval() is called. What’s the point? The object is invalid anyway, why wait until you use it?

    and an exception be thrown, though that would lead to serious increase
    in runtime.

    Have you profiled this? Don’t not use exceptions because you assume increase in runtime.

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

Sidebar

Related Questions

I need to make a base class enforce this: public class DialogForm : Form
I need to make a class Serializable. In this class I have a MyGuid
I need to make one instance of some class - and this one instance
I have a class that need to make some magic with every operator, like
I need to make a 2D convex hull function for a class assignment and
I have method in a class that I need to make sure is only
All I need is a way to make a property of one class only
I need to make a UML class diagram for a project. I used Sparx
I need to make a whole div(with class container) editable when the user clicks
I need to make special request to database through django. For example: class Model(models.Model):

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.