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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:04:19+00:00 2026-05-16T01:04:19+00:00

I am tying to throw an exception when a BigInteger is greater than Integer.MAX_VALUE.

  • 0

I am tying to throw an exception when a BigInteger is greater than Integer.MAX_VALUE. It will not allow me to throw that exception for the exponent case. I am not sure how to get it to throw an exception when the biginteger value is too large to pass into the BigInteger.pow() method.

Thanks in advance.

here is the toPostfix method:

public BigInteger evalPostfix(String postfix){
    BigInteger a, b;
    Stack stack = new Stack();

        for(int i=0; i<postfix.length(); i++){
            if(this.isOp(postfix.charAt(0)))
                throw new ArithmeticException("Malformed Postfix Expression");
            switch(postfix.charAt(i)){
                case '+':
                    a = (BigInteger)stack.pop();
                    b = (BigInteger)stack.pop();
                    stack.push(b.add(a));
                    break;
                case '-':
                    a = (BigInteger)stack.pop();
                    b = (BigInteger)stack.pop();
                    stack.push(b.subtract(a));
                    break;
                case '*':
                    a = (BigInteger)stack.pop();
                    b = (BigInteger)stack.pop();
                    stack.push(b.multiply(a));
                    break;
                case '/':
                    a = (BigInteger)stack.pop();
                    b = (BigInteger)stack.pop();
                    if(a == BigInteger.valueOf(0)){
                        throw new ArithmeticException("Cannot divide by 0");
                    }else{
                        stack.push(b.divide(a));
                    }
                    break;
                case '%':
                    a = (BigInteger)stack.pop();
                    b = (BigInteger)stack.pop();
                    stack.push(b.mod(a));
                    break;
                case '^':
                    a = (BigInteger)stack.pop();
                    b = (BigInteger)stack.pop();
                    if(b.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0)
                        throw new ArithmeticException("BigInteger value is too large");
                    stack.push(a.pow(b.intValue()));
                    break;
                default:
                    if(this.numbers.get(postfix.substring(i, i+1)) == null)
                        throw new NullPointerException(postfix.substring(i, i+1) + " is not mapped to any value");
                    stack.push(this.numbers.get(postfix.substring(i,i+1)));
            }
        }

    return (BigInteger)stack.pop();
}
  • 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-16T01:04:20+00:00Added an answer on May 16, 2026 at 1:04 am

    The way it is written, it should throw ArithmeticException("Negative Exponent Error") if the exponent is greater than Integer.MAX_VALUE. What happens when you try it?

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

Sidebar

Related Questions

I'm trying to make a call that might throw an exception due to server
BeginSend function does not throw exception when I disconnect iPad from Network. Interesting thing
I know that it's not safe to throw exceptions from destructors, but is it
I'm trying to throw an exception (without using a try catch block) and my
I am trying to use a class to throw an exception, the exception though
I'm trying to figure out whether the code located after throw new Exception in
I have an applet that throws this exception when trying to communicate with the
Trying to throw an exception in Haskell: import Control.Exception import Data.Typeable data MyException =
I'm trying to throw an exception in my code like this: throw RuntimeException(msg); But
I am using rhino mocks 3.5 and am trying to throw an exception in

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.