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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:46:19+00:00 2026-05-23T02:46:19+00:00

NSString *stringURL=[[NSString alloc] init]; stringURL=[stringURL stringByAppendingFormat:kSearchBarURL,text.text]; NSString *url = [NSString stringWithString:stringURL]; NSData *data1 =

  • 0
NSString *stringURL=[[NSString alloc] init];

stringURL=[stringURL stringByAppendingFormat:kSearchBarURL,text.text];

NSString *url = [NSString stringWithString:stringURL];

NSData *data1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];

NSString *responseids = [[NSString alloc] initWithData:data1 encoding:nil];

responseids = [responseids stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n\r\t"]];  

SBJsonParser *parser=[SBJsonParser new];

NSData  *data = [parser objectWithString:responseids error:nil];

NSMutableDictionary *searchURL = (NSMutableDictionary*)data;

I coded this i did not handle the exception for my code.

doing json and calling the service url and loading the data.

the application get crashes when my service is too low or no service found.

How to handle the exception for my code here..

Do I use @try @catch.
or
NSURLConnection for error handling.

Please help me out .

Thanks in advance.

  • 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-23T02:46:20+00:00Added an answer on May 23, 2026 at 2:46 am

    Whenever an API makes use of NSError, you should use this rather than wrapping things up in a try…catch block as NSError is designed exactly for this. I usually reserve @try for things where I am really not able to anticipate what might go wrong. If NSError is in the mix, then you know that there is a potential for a problem that you should be handling gracefully.

    More generally, your code has some strange stuff in it. You alloc init an empty NSString and then create a new string by appending a format. Not sure why you don’t just use [NSString stringWithFormat]. Once you have the string, you can create the URL without the NSString *url bit.

    You’re also using a synchronous call to what I assume is a remote server. This has the potential to bog down your application if/when the server is not available. You’re also not telling NSString what kind of encoding you expect your string to be in when it reads it from NSData. A better method depending on your server side would be to use NSString’s stringWithContentsOfURL:usedEncoding:error: method. I would recommend that you use the various NSURLConnection callbacks. Have a look at the URL Loading System Programming Guide on Using NSURLConnection The NSURLConnection delegate methods are the ones you want to implement to provide this asynchronous processing.

    For your trimming, you might be interested in the +whitespaceAndNewlineCharacterSet method on NSCharacterSet.

    Finally, for your JSON parsing, you might be interested in the category that the SBJSON code adds to NSString, particularly -JSONValue which will give you the dictionary or array representation (as appropriate) of the NSString when parsed as JSON by SBJSON.

    HTH

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

Sidebar

Related Questions

Like this: NSString *stringURL = @appname://; NSURL *url = [NSURL URLWithString:stringURL]; [[UIApplication sharedApplication] openURL:url];
NSString *reqURL = [NSString stringWithFormat:@%@/login,SERVER_URL]; NSMutableURLRequest *req = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:reqURL]]; [req setValue:@application/x-www-form-urlencoded forHTTPHeaderField:@content-type];
NSString *urlAddress = @http://www.test.com/test.jsp?Query=哈囉; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSString *navTitle = self.navigationItem.title; NSURL *address = [NSURL URLWithString:[NSString stringWithFormat:@http://www.twostepmedia.co.uk/json.php?q=%@,navTitle]]; responseData = [[NSMutableData data]
NSString *qry=@UPDATE TABLE USERBASIC SET F_NAME='%@',M_NAME='%@',L_NAME='%@' WHERE REGISTRATIONID='%@'; NSString *updtQuery=[[NSString alloc] stringWithFormat:qry,fname.text,mname.text,lname.text,userInformationId]; NSLog(@try UPDATE
- (NSString *)allocString{ NSString *str = [[NSString alloc] init]; return str; } - (void)viewDidLoad{
NSString *url = [NSString stringWithString: @mailto:?subject=Wallpapers%203d%20App&body=Have%20fun%20with%20this%20unique%20wallpaper%20app]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]]; I am
NSString *path = [[NSBundle mainBundle] pathForResource:[arraySub objectAtIndex:indexPathHere.row] ofType:@mp3]; NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
NSString *latitude = [[NSString alloc] initWithFormat:@%g°, coordinate.latitude]; NSString *longitude = [[NSString alloc] initWithFormat:@%g°, coordinate.longitude];
NSString *msg = [[NSString alloc]initWithFormat:@Hello %s, What do you do, (self.isUser ? @User :

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.