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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:19:02+00:00 2026-05-28T14:19:02+00:00

I want to try to create an image using NSdata. If imageWithData: method of

  • 0

I want to try to create an image using NSdata. If imageWithData: method of UIImage can create it successfully, i will follow a path but if it cannot create i want to follow another way.

Is this even possible?

I tried

    @try {
        im = [UIImage imageWithData:data];
        NSLog(@"Trying");
    }
    @catch (NSException * e) {
        NSLog(@"Exception");    
        anotherData = doSomethingWithData(data)
        im = [UIImage imageWithData:anotherData];
    }
    @finally {
        NSLog(@"Final");
        [self.questionList addObject:im];
    }

but it causes app to crash.

How can I catch this exception without causing app to crash?

Exception is this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'

Code does not create image from data but still it does not throws an exception or anything about it. Is there a way that I can understand if image is created or not.

  • 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-28T14:19:03+00:00Added an answer on May 28, 2026 at 2:19 pm

    You get the error, because im remains nil and you are not allowed to add nil to an array.

    You could do it like that:

    im = [UIImage imageWithData:data];
    
    if(im == nil) {
        anotherData = doSomethingWithData(data)
        im = [UIImage imageWithData:anotherData];
    }
    
    if(im != nil)
        [self.questionList addObject:im];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a login page, it can easy implement using Ruby on
I want to upload the image using the .NET webservices and that will be
I want to create user profile with image. That user can upload his photo,
I want to create a servlet that will allow me to upload image files
I want to Create a new User using Custom Membership Provider but I don't
I tried to create image from BLOB. I try following code but it is
I want to create a BufferedImage from a image but it not run. what
I want my code to automatically try multiple ways to create a database connection.
I want to try to convert a string to a Guid, but I don't
I want to try out SICP with Python. Can any one point to materials

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.