Welcome to MacForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

catching exceptions help needed.

 
   Macintosh computer (Home) -> Programmer Help RSS
Next:  Repairing Midplane on G5 iMac  
Author Message
Santa Claus

External


Since: Sep 24, 2005
Posts: 53



(Msg. 1) Posted: Sun Feb 24, 2008 4:29 pm
Post subject: catching exceptions help needed.
Archived from groups: comp>sys>mac>programmer>help (more info?)

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.

 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 53



(Msg. 2) Posted: Sun Feb 24, 2008 11:15 pm
Post subject: Re: catching exceptions help needed. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Santa Claus wrote:

> 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.

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...

 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
Ben Artin

External


Since: Jun 20, 2005
Posts: 54



(Msg. 3) Posted: Mon Feb 25, 2008 11:41 am
Post subject: Re: catching exceptions help needed. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Santa Claus wrote:

> 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...

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

--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>
 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 53



(Msg. 4) Posted: Mon Feb 25, 2008 5:36 pm
Post subject: Re: catching exceptions help needed. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Ben Artin wrote:

> In article ,
> Santa Claus wrote:
>
> > 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...
>
> 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.

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.
 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 53



(Msg. 5) Posted: Tue Feb 26, 2008 6:25 pm
Post subject: Re: catching exceptions help needed. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Santa Claus wrote:

> 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.

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];
 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
David Phillip Oste

External


Since: Apr 25, 2004
Posts: 694



(Msg. 6) Posted: Tue Feb 26, 2008 6:28 pm
Post subject: Re: catching exceptions help needed. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Santa Claus wrote:

> 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...

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

long long freespace =
[[dict objectForKey: NSFileSystemFreeSize] longLongValue];
 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
David Phillip Oste

External


Since: Apr 25, 2004
Posts: 694



(Msg. 7) Posted: Tue Feb 26, 2008 6:32 pm
Post subject: Re: catching exceptions help needed. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Santa Claus wrote:

> 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.

@try {
[myFile writeData:myData];
} @catch(NSException *except) {
// <-- if we get here, the exception occurred.
NSLog(@"%@ %@\n", [except name], [except reason]);
}
 >> Stay informed about: catching exceptions help needed. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Catching uncaught exceptions in NSTimer -

_T in ctype.h -- needed? - The /usr/include/ctype.h file in Darwin 7.2 has a block of macros (_CTYPE_A, _CTYPE_C, etc.), and then a block of synonyms (_A = _CTYPE_A, etc) with the comment "backward compatibility". Alas, this collides with cross-platform Mac-Win32 goals....

CFBundle help needed - I've got a command-line Mach-O app that needs to load a CFM shared library inside of a bundled app that resides in the same directory, like so: command_line_app MainApp /Contents /Resources CFMLib My first though was to use..

web design advices needed - I need to design a Comment page in a site where 1- visitor will enter their comments 2- comments are stored 3- the display wil have to seems being 'handwritten' (using a specific handwriting font...) 1-form design using CSS is quite easy 2- I'll use an...

some sample code needed..ASAP.. - Hi, I am developing a Carbon Application using Project Builder which comes with Mac OS X 10.1 version. I am trying to make use of Apple Events. One of my basic ideas is to establish interprocess communication. For this I suppose we have to make use of....
   Macintosh computer (Home) -> Programmer Help All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]