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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:14:40+00:00 2026-05-31T11:14:40+00:00

Currently I am making a Calculator that allows the user to type out the

  • 0

Currently I am making a Calculator that allows the user to type out the formula they wish.

Ex. ((1+1)**9)+2)

This works just fine, I have used two methods for calculating this.

First:

    answer = [[NSExpression expressionWithFormat:typeTo.text, nil] expressionValueWithObject:nil context:nil];
    typeTo.text = [NSString stringWithFormat:@"%@", answer];
    answerLabel.text = [NSString stringWithFormat:@"ANS { %@ }", answer];

Second:

     answer = [GCMathParser evaluate:typeTo.text];

Both of these calculate the problem without difficulty. But if the user types in:

(1+1)) [two brackets]

Both ways crash. This is one example of many different syntax errors. Is there a way to easily prevent this?

.

Additional info:
This is the way the second method catches the error:

#ifdef __COCOA_IMPLEMENTATION__
[NSException raise:@"Error in expression" format:@"error = %s", errStr];
#endif

THANKS 😀

  • 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-31T11:14:42+00:00Added an answer on May 31, 2026 at 11:14 am

    I haven’t used either of those but based on the additional info, it may be throwing an NSException.

    If that’s the case, you can catch it and handle it. It looks like it might format a useful message telling you what’s wrong with with expressions.

    @try
    {
        // do work
    }
    @catch(NSException* ex)
    {
        // handle
    }
    

    https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html

    Also, look to see if those libraries offer functions that pass in a ref to NSError. If so, you can use that.

    There’s also DDMathParser which is supposed to be a modern math parser and it looks like it takes NSError. Might be worth a look.

    http://github.com/davedelong/DDMathParser

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

Sidebar

Related Questions

I'm currently making an iPhone app that has PDF viewing a crucial part of
I'm currently making some system that will gather statistical reports from different sites, for
I'm making an application that gives clients and approximate loan offer (they are later
I am currently making a software that can be used to playback training packages.
i'm currently making search engine for a website content (only for searching within that
I'm working on an assignment which involves making an RPN calculator. I am currently
I'm currently making an iphone web app based on Google App Engine (python). I
I'm currently making a front end to display license information for my companies software
I'm currently making a GWT project where I display some HTML in a RichTextArea
I have a question about tables in MySQL. I'm currently making a website where

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.