Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / February 2008



Tip: Looking for answers? Try searching our database.

catching exceptions help needed.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Santa Claus - 24 Feb 2008 21:29 GMT
i would appreciate some assistance in one of two things.

1) determine free space on a local volume
2) catch and handle an exception caused by the following:

2008-02-24 15:04:48.721 Avalon[26929] An uncaught exception was raised
2008-02-24 15:04:48.721 Avalon[26929] *** -[NSConcreteFileHandle
writeData:]: No space left on device
2008-02-24 15:04:48.721 Avalon[26929] *** Uncaught exception:
<NSFileHandleOperationException> *** -[NSConcreteFileHandle writeData:]:
No space left on device
Feb 24 15:04:50 nameserver crashdump[26931]: Avalon crashed
Feb 24 15:04:50 nameserver crashdump[26931]: crash report written to:
/Library/Logs/CrashReporter/Avalon.crash.log

i checked apple's site and no help there, nothing that points to
"errors" or "exceptions" that make any sense to me.  i'm not trying to
get the NSString of the "no space left on volume", i'm trying to ignore
that message (it's handled within my code anyway) or get the drive space
available so i can eliminate the possibility of it coming up.
Santa Claus - 25 Feb 2008 04:15 GMT
> i would appreciate some assistance in one of two things.
>
[quoted text clipped - 16 lines]
> that message (it's handled within my code anyway) or get the drive space
> available so i can eliminate the possibility of it coming up.

it took a bit to remember the web site that has all of it but this is
what cocoabuilder.com had to say

Re: Detecting low disk space
FROM : Fritz Anderson
DATE : Fri Apr 09 17:48:19 2004

NSDictionary *        dict = [[NSFileManager defaultManager]
fileSystemAttributesAtPath: @"/"];
unsigned            freeSpace = [[dict objectForKey:
NSFileSystemFreeSize]
unsignedIntValue];

This will give you the free disk space on the startup volume. I can't
vouch for whether it is wise (or possible) to take up all the free
space.

now to test it out...
Ben Artin - 25 Feb 2008 16:41 GMT
> Re: Detecting low disk space
> FROM : Fritz Anderson
[quoted text clipped - 11 lines]
>
> now to test it out...

This won't save you. No matter how hard you try to check free disk space, other
apps can fill it up while you aren't looking, and when they do, you will still
need to handle an exception.

The only robust way to handle running out of disk space is to cope with the
error when it happens; it may be helpful, but it is never sufficient, to try to
avoid running into the error in the first place.

hth

Ben

Signature

If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

Santa Claus - 25 Feb 2008 22:36 GMT
> > Re: Detecting low disk space
> > FROM : Fritz Anderson
[quoted text clipped - 22 lines]
> to
> avoid running into the error in the first place.

agreed,  this brings me to the other point.  how do i trap the
exception?  is it with the notification manager or exception manager?  
the exception manager appears to be intended to send exceptions not
receive them.

oh, i wish for the good old days of simply checking the ioresult and
determining what it was and acting on it that way.  write a file, disk
gets full and it doesn't write and then sends back an error to the
method that called it and that method can handle it directly instead of
indirectly.
Santa Claus - 26 Feb 2008 23:25 GMT
> agreed,  this brings me to the other point.  how do i trap the
> exception?  is it with the notification manager or exception manager?  
[quoted text clipped - 6 lines]
> method that called it and that method can handle it directly instead of
> indirectly.

ok, i found out why i can't find any references to the exception
manager, it wasn't included in my project frameworks.  i added that and
then found out a whole bunch of things and got it to trap the error.

when i return the BOOL of NO, it continues to crash the program.  when i
return YES, it doesn't crash the program but doesn't resume the thread
where it left off either.  yes, i know i need to actually TEST for the
proper exception to handle it properly but this is a short and dirty
test to see what's supposed to happen.

- (BOOL)exceptionHandler: (NSExceptionHandler *) sender
  shouldHandleException: (NSException *) exception
                   mask: (unsigned int) aMask;
{
 NSLog(@"ignore the above exception, it's being handled.");
 NSLog(@"exception sender = %@",  sender);
 NSLog(@"exception        = %@",  exception);
 NSLog(@"exception mask   = %ld", aMask);

 // these things i added to try to close the thread properly since it
didn't close properly with just the return.
 [self echotext: [NSMutableString stringWithString: @"done with zeroize
function\n"]];
 [mapWindowPool release];

 return YES;
}

 NSExceptionHandler *handler = [NSExceptionHandler
defaultExceptionHandler];
 [handler setExceptionHandlingMask: NSHandleUncaughtExceptionMask];
 [handler setDelegate: self];
David Phillip Oster - 27 Feb 2008 02:28 GMT
> it took a bit to remember the web site that has all of it but this is
> what cocoabuilder.com had to say
[quoted text clipped - 14 lines]
>
> now to test it out...

NO! the free space can easily overflow a 32-bit unsigned. Use the correct
type:

long long freespace =
 [[dict objectForKey: NSFileSystemFreeSize] longLongValue];
David Phillip Oster - 27 Feb 2008 02:32 GMT
> i would appreciate some assistance in one of two things.
>
[quoted text clipped - 16 lines]
> that message (it's handled within my code anyway) or get the drive space
> available so i can eliminate the possibility of it coming up.

@try {
 [myFile writeData:myData];
} @catch(NSException *except) {
  // <-- if we get here, the exception occurred.
  NSLog(@"%@ %@\n", [except name], [except reason]);
}
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.