Re: Exception-like behavior in save panel used for file choose
Re: Exception-like behavior in save panel used for file choose
- Subject: Re: Exception-like behavior in save panel used for file choose
- From: Quincey Morris <email@hidden>
- Date: Fri, 31 Jul 2009 09:58:22 -0700
On Jul 30, 2009, at 23:04, Barry Press wrote:
NSString *sFile = [textLogPath stringValue];; //
stringByStandardizingPath;
NSString *sFileWithoutLast = [sFile
stringByDeletingLastPathComponent];
NSString *sFileOnly = [sFile substringFromIndex:[sFileWithoutLast
length]+1];
...
This latter code works properly so long as the file that will be the
target of the append -- the target of the save panel -- does not
exist. In that event, the runModal comes back and I can extract the
name. If the file *does* exist, however, then a panel comes up that
asks if it's ok to replace the file, and if I agree to replace, not
only the choose panel closes, so does my settings panel - I'm dumped
all the way back to the app that invoked showPreferencePane.
...
Any ideas on why the panel closes around me?
(Side note: anyone who wants to critique my code for splitting a
file name off a path, please let her rip!)
As others have suggested, this is one of those "almost always"
situations: When you see a mysterious gross transfer of control in a
Cocoa application, it's almost always because an exception occurred,
and there'll be an error message in the console log. So, yes, you can
break on objc_exception_throw, but the first step is always to
actually check the console log.
You didn't say whether your app uses garbage collection or retain/
release. If the latter, you need to review memory management, because
you're not retaining (and therefore don't own) any of the strings
here. If your save panel delegate uses any of the strings created
before the "runModal", it's possible they're getting deallocated too
early.
I don't really want to critique your code, but it does make me wonder:
-- Why are you using NSSavePanel for (apparently) getting an existing
file to append to?
-- Why are you using "[sFile substringFromIndex ...]" to get the last
path component, when "[sFile lastPathComponent]" would seem to be the
logical choice?
-- Why are you invoking *both* setAllowedFileTypes: *and*
setRequiredFileType:, with different parameters, when they're
documented to be alternatives to each other?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden