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

  • Home
  • SEARCH
  • 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 6036979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:00:20+00:00 2026-05-23T06:00:20+00:00

I am building a app with many different parts which access remote api calls

  • 0

I am building a app with many different parts which access remote api calls (both my own, and others). There are many errors that might happen, and to exacerbate the problem, different libraries handle these errors differently.

Essentially, i would like to use the same error handling blocks for all these remote calls.

This is how i would do it with Ruby, but i am not that sure how to manipulate objective c in the same manner

  //universal function to handle standard remote errors across errors
  def universal_handling
    begin
      yield
    rescue Exception => e
      // handle different exceptions accordingly  
      // allow crash if unexpected exception
    end
  end

  //how i would use the above block
  universal_handling{  //any of my remote call here  }

So, i have 2 questions (sample code very much appreciated)

  1. How would I write the equivalent code in Objective-C? It is critical that I can use the same handling block throughout the app
  2. In iOS dev, is this good practice?

Thanks for any help rendered! Error handling can be a major pain in the ass, so i do want to get this right early on =)

Notes:

  1. Blocks are perfectly fine. I am not intending to support < 4.2 versions.
  2. I read most of the articles out there, but none answers how you can use blocks to write “wrappers” for a specific set of calls.
  • 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-23T06:00:21+00:00Added an answer on May 23, 2026 at 6:00 am

    You can do something very similar with blocks:

    typedef void(^WrappableBlock)(void);
    
    ^(WrappableBlock block) {
      @try {
        block();
      }
      @catch(...)
      }
        //handle exception
      }
    }
    

    However, it’s very important to realize that the Cocoa (and CocoaTouch) libraries are not exception-safe. Throwing an exception through Cocoa frameworks will lead to all sorts of problems as the frameworks will not properly handle or clean up from the exceptions, leaving your application in a possibly inconsistent state. The correct Cocoa-style is to use NSError and return flags to indicate error conditions. This is neither better nor worse than using exceptions, just a different philosophy.

    To do something similar to your universal_handling with NSError is not quite so straight forward because it will require that anything you call comply with the NSError pattern. That said:

    typedef BOOL(^WrappableBlock)(NSError**);
    
    ^(WrappableBlock block, NSError **err) {
      BOOL success = block(err);
      if(!success) {
        // handle error
      }
    
      return success;
    }
    

    would wrap any method that takes just an NSError** and returns a BOOL to indicate the presence of an error. Obviously the utility of this wrapper is limited as you’ll have to wrap any interesting method in an other block to handle any other parameters. Of course, since it’s the NSError** pattern, you can always just handle the errors when/where you want and pass NULL as the NSError** parameter where you don’t care (ignoring the return value).

    One final note: if you are using libraries that may throw exceptions, you must catch those exceptions within the scope of the library call and handle them. Do not let the exceptions propagate as they might then propagate through Cocoa framework code. Thus, the utility of the universal_handling block you propose is limited.

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

Sidebar

Related Questions

I am building an app that talks to an Access database via OleDB/Jet. There
I'm currently building a Java app that could end up being run on many
I'm building my first Rails project - its a ToDo app, which are supposed
I'm building a web app and need to implement how many times the item
I'm building an app that uses phone numbers to perform different tasks, and recently
I'm building an app that authors would (hopefully) use to help them, uh.. author
We're building an app that stores hours of operation for various businesses. What is
I'm building an app in Ruby on Rails, and I'm including 3 of my
So I'm building an app that uses win32's SendMessage as IPC. I'm using FindWindow
I'm building a app that need manage money datatype. I'm new on Obj-c, so

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.