• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: try catch not catching...hmm
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: try catch not catching...hmm


  • Subject: Re: try catch not catching...hmm
  • From: Jerrod Fowkes <email@hidden>
  • Date: Thu, 2 Nov 2006 06:55:38 -0800 (PST)

Jerrod Fowkes <email@hidden> wrote:


---------------------------------
We have the perfect Group for you. Check out the handy changes to Yahoo! Groups.Date: Thu, 2 Nov 2006 05:50:44 -0800 (PST)
From: Jerrod Fowkes <email@hidden>
Subject: Re: try catch not catching
To: Sherm Pendley <email@hidden>

 "If so, I find that exceedingly odd, given that you're not working
with any filehandles in the above. The exception above is what you'd
get if you were trying to read from a file that had already been
closed, or a problem similar to that.

How are you creating the dataRep NSData instance?"


Yes I am working with fileHandles. The code is structured like so

else
{
     try
    {
                    NSFileHandle *fileHandle;
            fileHandle = [NSFileHandle fileHandleForReadingAtPath: [appPath stringByAppendingString: libraryFile]];

            NSData* dataRep;
            dataRep = [fileHandle readDataToEndOfFile];

            someNSMutableDictionaryPointer = [[NSPropertyListSerialization propertyListFromData: dataRep
                                                                 mutabilityOption: NSPropertyListMutableContainers
                                                                           format:  &format
                                                                 errorDescription: &error] retain];

[fileHandle closeFile]; //I suppose I could call this right after I readDataToEnd...

    }
    ..catch..finally

}

sorry about the formatting, Yahoo mail kinda sucks at that.

"The above code isn't reading from a file, it's reading from an NSData
instance. It might be reading from a file indirectly," Right I suppose I skipped a step there when I should have posted that portion of the code, but yes, I am reading from an NSData object that contains the buffer from the file.

Well here is the complete code of what I am attempting to do. Right below here is the original implementation that will cause the application to bomb. I believe it has something to do with the serialized file that I am loading. It could be somehow corrupt. At any rate, I re-wrote this portion of the code, it's the same code, nothing really has changed except for another try catch. REALLY ODD.

//original
else
    {
        //We need to pull some data out of there.
        @try {

            #if defined(PRES_DEBUG) || defined(PRES_LOG_EXT)
                [self LogMessage: @"Retreiving music data from library."];
            #endif

             NSFileHandle *fileHandle;
            fileHandle = [NSFileHandle fileHandleForReadingAtPath: [appPath stringByAppendingString: musicLibraryFile]];

            NSData*  dataRep;
            dataRep = [fileHandle readDataToEndOfFile];

            NSString* error;
            NSPropertyListFormat format;
            audioNewsMusicLibrary = [[NSPropertyListSerialization propertyListFromData: dataRep
                                                                  mutabilityOption: NSPropertyListMutableContainers
                                                                            format: &format
                                                                 errorDescription: &error] retain];

             if(!audioNewsMusicLibrary)
            {
                audioNewsMusicLibrary = nil;
                audioNewsMusicLibrary =  [[NSMutableDictionary alloc] init];
            }

            [fileHandle closeFile];
        }
        @catch (NSException * e) {
            [self LogMessage: @"Error Pulling MusicLibrary from app path"];
        }
        @finally {
        }
     }

    Here is the new implementation that majically works.
    else
    {
        //We need to pull some data out of there.
        NSData* dataRep;
        NSFileHandle *fileHandle;
        @try
         {

            #if defined(PRES_DEBUG) || defined(PRES_LOG_EXT)
                [self LogMessage: @"Retreiving music data from library."];
            #endif

            fileHandle = [NSFileHandle fileHandleForReadingAtPath:  [appPath stringByAppendingString: musicLibraryFile]];
            dataRep = [fileHandle readDataToEndOfFile];
        }
        @catch (NSException * e)
        {
            [self LogMessage: @"Error Pulling  MusicLibrary from app path"];
        }

        NSString* error;
        NSPropertyListFormat format;
        @try
        {
            audioNewsMusicLibrary = [[NSPropertyListSerialization propertyListFromData: dataRep
                                                                  mutabilityOption: NSPropertyListMutableContainers
                                                                            format: &format
                                                                 errorDescription: &error]  retain];

            if(!audioNewsMusicLibrary)
            {
                audioNewsMusicLibrary = nil;
                 audioNewsMusicLibrary = [[NSMutableDictionary alloc] init];
            }
        }
        @catch (NSException * e) {
            [self LogMessage: @"Corrupt music library."];
        }

        [fileHandle closeFile];
    }

As I said, nothing really new. BTW it doesn't crash my application, but when it does load the NSMutableDictionary from the Data object, it doesn't have any key-value pairs, which is odd because the NSData Object in fact does have the same amount of bytes when loaded that are in the file. So something is there, it just seems that NSPropertyListMutableContainers doesn't like that particular buffer. Any ideas? -Jerrod Fowkes

---------------------------------
Everyone is raving about the  all-new Yahoo! Mail.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: try catch not catching (From: Jerrod Fowkes <email@hidden>)

  • Prev by Date: Re: try catch not catching
  • Next by Date: Re: Posting Global hot keys from a Cocoa app
  • Previous by thread: Re: try catch not catching
  • Next by thread: Re: [NSCalendar currentCalendar] leak
  • Index(es):
    • Date
    • Thread