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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:07:13+00:00 2026-06-08T12:07:13+00:00

How do I do this, I have a class called LargeInteger that stores a

  • 0

How do I do this,

I have a class called LargeInteger that stores a number of maxmimum 20 digits.
I made the constructor

LargeInteger::LargeInteger(string number){ init(number); }

Now if the number is > LargeInteger::MAX_DIGITS (static const member) i.e 20 i want to not create the object and throw an exception.

I created an class LargeIntegerException{ … }; and did this

void init(string number) throw(LargeIntegerException);
void LargeInteger::init(string number) throw(LargeIntegerException)
{
    if(number.length > MAX_DIGITS)
    throw LargeIntegerException(LargeIntegerException::OUT_OF_BOUNDS);
    else ......
}

So now i modified the constructor

LargeInteger::LargeInteger(string number)
{ try {init(number);} catch(LargeIntegerExceptione) {...} }

Now I have 2 questions
1.Will the object of this class be created incase an exception is thrown?
2.How to handle it if the above is true?

  • 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-06-08T12:07:14+00:00Added an answer on June 8, 2026 at 12:07 pm

    No, if an exception is thrown in the constructor, the object is not constructed (provided you don’t catch it, like you do).

    So – don’t catch the exception, rather let it propagate to the calling context.

    IMO, this is the right approach – if the object can’t be initialize directly, throw an exception in the constructor and don’t create the object.

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

Sidebar

Related Questions

I have this class called Hero that has the following attributes. String is for
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have this small class called City that simply holds some information about a
So I have this problem in PHP, I have a class called unit that
this is my escenary, I Have a class called Plantilla that contains severals propertyes
I have class called GroupSelect and made a collection List(Of GroupSelect)() . Now I
I have this class called Table: class Table { public string Name { get
i have this class called MemoryManager, it is supposed to implement a simple smart
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I'm trying to validate an ID. I have this class called ManejadorTickets in 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.