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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:49:16+00:00 2026-06-04T05:49:16+00:00

I’m creating a framework for use by a Cocoa Application on 10.6 and later.

  • 0

I’m creating a framework for use by a Cocoa Application on 10.6 and later.

The purpose of the framework is to parse a text file.

Obviously, there are errors that could occur, such as file not found, permissions issues, etc.

What is the right way to handle errors within the framework and notify the host application?

My thoughts were:

  1. Do nothing and let the host application catch any exceptions.

  2. Have the host application register its first responder with the framework, catch any exceptions, convert them into NSError and pass them to the host app’s responder chain.

Do either of those options make sense? Are there other options? What’s the right way to handle this?

I have read the error and exception handling guides, but they don’t cover this situation and only describe error handling within the application itself.

  • 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-04T05:49:17+00:00Added an answer on June 4, 2026 at 5:49 am

    I would say the correct way is to use NSError directly yourself in all methods that can error. I have done this recently with a utility class I created, and it works very well. You then allow the application to decide what do to with the error (crash, log, something else) and the framework doesn’t need to worry.

    Here are the private class methods I used to create the error objects, allowing for underlying POSIX errors (errno etc.):

    #pragma mark - Private Methods
    
    - (NSError *)error:(NSString *)localizedDescription
                  code:(EZipFileError)code
       underlyingError:(NSError *)underlyingError
    {
        NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary];
        [errorDetail setValue:localizedDescription forKey:NSLocalizedDescriptionKey];
        if (underlyingError != nil)
        {
            [errorDetail setValue:underlyingError forKey:NSUnderlyingErrorKey];
        }
        return [NSError errorWithDomain:@"MyErrorDomain"
                                   code:(NSInteger)code
                               userInfo:errorDetail];
    }
    
    - (NSError *)error:(NSString *)localizedDescription
                  code:(EZipFileError)code
    {
        return [self error:localizedDescription
                      code:code
           underlyingError:nil];
    }
    
    - (NSError *)error:(NSString *)localizedDescription
                  code:(EZipFileError)code
            posixError:(int)posixError
    {
        NSMutableDictionary *underlyingErrorDetail = [NSMutableDictionary dictionary];
        [underlyingErrorDetail setValue:[NSString stringWithUTF8String:strerror(posixError)]
                                 forKey:NSLocalizedDescriptionKey];
        NSError *underlyingError = [NSError errorWithDomain:NSPOSIXErrorDomain
                                                        code:posixError
                                                    userInfo:underlyingErrorDetail];
        return [self error:localizedDescription
                      code:code
           underlyingError:underlyingError];
    }
    

    Which is used as follows:

    if (![self isOpen])
    {
        if (error != NULL)
        {
            *error = [self error:@"File is not open"
                            code:ErrorNotOpen];
        }
        return nil;
    }
    

    Here’s an example that uses the underlying POSIX error version of the method:

    filefp = fopen([filename UTF8String], "rb");
    if (filefp == NULL)
    {
        if (error != NULL)
        {
            *error = [self error:@"Failed to open file"
                            code:ErrorOpenFileFailed
                      posixError:errno];
        }
        return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.