try catch not catching

  • I have this code :

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

            }
            @catch (NSException * e) {
                [self LogMessage: @"Corrupt library."];
            }
            @finally {

            }

    it crashes my application right inside the try block. What gives?
    I have also tried NS DURING. -Jerrod Fowkes

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • For whatever reason, the GDB doesn't appear to be stopping at my break point, at the correct spot in memory.

    I have it set on the line of code inside the try catch but in my Debugger Console, it's showing things that I am logging to the console in a function that is being called after this try / catch. I am guessing that this is a nromalty with GDB? I switched from using DWARF to Stabs, it's still giving me the same. -Jerrod

    Jerrod Fowkes <jerrodfowkes...> wrote: I have this code :

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

            }
            @catch (NSException * e) {
                [self LogMessage: @"Corrupt library."];
            }
            @finally {

            }

    it crashes my application right inside the try block. What gives?
    I have also tried NS DURING. -Jerrod Fowkes

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
    _______________________________________________
    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list      (<Cocoa-dev...>)
    Help/Unsubscribe/Update your Subscription:
    http://lists.apple.com/mailman/options/cocoa-dev/<jerrodfowkes...>

    This email sent to <jerrodfowkes...>


    ---------------------------------
    Get your email and see which of your friends are online - Right on the  new Yahoo.com
  • On Nov 1, 2006, at 3:27 PM, Jerrod Fowkes wrote:

    > For whatever reason, the GDB doesn't appear to be stopping at my
    > break point, at the correct spot in memory.

    Have you tried disabling all compiler optimization with -O0?

    Debugger problems like you're describing can happen if the optimizer
    has rearranged your code.

    sherm--

    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
  • Sherm Pendley <sherm...> wrote: On Nov 1, 2006, at 3:27 PM, Jerrod Fowkes wrote:

    Have you tried disabling all compiler optimization with -O0?

    Yes, that is set. It seems as though that is set by default. -Jerrod

    ---------------------------------
    Get your email and see which of your friends are online - Right on the  new Yahoo.com
  • On 1 nov 2006, at 21.14, Jerrod Fowkes wrote:

    > it crashes my application right inside the try block. What gives?
    > I have also tried NS DURING. -Jerrod Fowkes

    Note that an exception handler only catches exceptions, not a real
    "crash" of the program.
    What type of crash are you seeing?

    I have to agree with Sherm that if your breakpoint doesn't break, it
    might be because of optimizations. Make sure that it's disabled - and
    check both project and target build settings! Also make sure that the
    source code you're looking at is matching your binaries - when in
    doubt, make a clean build.

    j o a r
  • j o a r <joar...> wrote:
    Note that an exception handler only catches exceptions, not a real
    "crash" of the program.
    What type of crash are you seeing?

    I have to agree with Sherm that if your breakpoint doesn't break, it
    might be because of optimizations. Make sure that it's disabled - and
    check both project and target build settings! Also make sure that the
    source code you're looking at is matching your binaries - when in
    doubt, make a clean build.

    Well, I am getting better debugging results. I didn`t realize that it had to be set for both project and build, so I am good there..

    Uncaught exception: <NSFileHandleOperationException> *** -[NSConcreteFileHandle fileDescriptor]: Bad file descriptor

    is the error I am getting, my program doesn`t log what is in my catch block.
    I have noticed that the file that I am reading from ( the serialized NSMutableDictionary ) seems to be corrupt...because if I delete it, then save some stuff to it, and read it back in then it`s fine.

    I wasn`t aware that when reading a simple NSPropertyListSerialization from a file wouldn`t throw exceptions. Doesn`t seem to be stable.

    the file is 24K, so I don`t think that would be a problem. I am also storing and reading it in as binary and not as xml.

    -Jerrod


    ---------------------------------
    Everyone is raving about the  all-new Yahoo! Mail.
  • On Nov 1, 2006, at 4:49 PM, Jerrod Fowkes wrote:

    > Uncaught exception: <NSFileHandleOperationException> *** -
    > [NSConcreteFileHandle fileDescriptor]: Bad file descriptor
    >
    > is the error I am getting

    Are you getting that from the code you posted earlier?

    > @try
    > {
    > someNSMutableDictionaryPointer =
    > [[NSPropertyListSerialization propertyListFromData: dataRep
    >
    > mutabilityOption: NSPropertyListMutableContainers
    >
    > format: &format
    >
    > errorDescription: &error] retain];
    >
    > }

    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?

    > I wasn`t aware that when reading a simple
    > NSPropertyListSerialization from a file wouldn`t throw exceptions.

    The above code isn't reading from a file, it's reading from an NSData
    instance. It might be reading from a file indirectly, if you created
    the NSData instance with one of NSData's ...withContentsOfMappedFile:
    creation methods. That's why I'm curious about how you created the
    NSData instance.

    sherm--

    Web Hosting by West Virginians, for West Virginians: http://wv-www.net
    Cocoa programming in Perl: http://camelbones.sourceforge.net
  • ---------------------------------
    We have the perfect Group for you. Check out the handy changes to Yahoo! Groups."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.

    -Jerrod Fowkes


    ---------------------------------
    Cheap Talk? Check out Yahoo! Messenger's low  PC-to-Phone call rates.
  • Jerrod Fowkes <jerrodfowkes...> 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 <jerrodfowkes...>
    Subject: Re: try catch not catching
    To: Sherm Pendley <sherm...>

    "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.
previous month november 2006 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
Go to today