Catch exception in NSArrayController

2009-09-17 Thread Konrad Windszus
I have a classical binding usecase: A NSArrayController is used for  
displaying the columns of a NSTableView. The columns itself therefore  
use the arrangedObject method of the NSArrayController. In the get  
methods of the model itself (which normally return an NSString* which  
should be displayed in the column), there could occur an exception. I  
want to catch that exception in the NSArrayController. I therefore  
subclassed the NSArrayController and overwrote valueForKeyPath with a  
simple:


- (id)valueForKeyPath:(NSString *)keyPath {
try {
[super valueForKeyPath:keyPath];
}
catch (...) {
		// want to get here, if there is an exception thrown within the  
model class

}
}

Unfortunately it is only called with arrangedObjects. At that point no  
exception is thrown yet. Somewhere after that a valueForKeyPath must  
be executed on that returned arrangedObjects. Since I have not  
subclassed this proxy class, I cannot intercept its valueForKeyPath  
method and therefore cannot catch the exception. Is there a simple way  
to catch exceptions in the controller class which is thrown during  
calling a get method (over binding mechanims)?

Thanks for any help.
Konrad
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Catch exception in NSArrayController

2009-09-17 Thread Sean McBride
On 9/17/09 1:26 PM, Konrad Windszus said:

I have a classical binding usecase: A NSArrayController is used for
displaying the columns of a NSTableView. The columns itself therefore
use the arrangedObject method of the NSArrayController. In the get
methods of the model itself (which normally return an NSString* which
should be displayed in the column), there could occur an exception. I
want to catch that exception in the NSArrayController. I therefore
subclassed the NSArrayController and overwrote valueForKeyPath with a
simple:

- (id)valueForKeyPath:(NSString *)keyPath {
   try {
   [super valueForKeyPath:keyPath];
   }
   catch (...) {
   // want to get here, if there is an exception thrown within the
model class
   }
}

Unfortunately it is only called with arrangedObjects. At that point no
exception is thrown yet. Somewhere after that a valueForKeyPath must
be executed on that returned arrangedObjects. Since I have not
subclassed this proxy class, I cannot intercept its valueForKeyPath
method and therefore cannot catch the exception. Is there a simple way
to catch exceptions in the controller class which is thrown during
calling a get method (over binding mechanims)?

What's this exception you speak of?  Are you throwing or is the system?

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Catch exception in NSArrayController

2009-09-17 Thread Kyle Sluder
Exceptions are used for programmer error in Cocoa. They are not a  
general error signaling mechanism.


There are a few unfortunate exceptions, though: Distributed Objects  
and Objective-C++. If you are not using these technologies, you should  
not be throwing or catching exceptions as a control-flow technique.  
Cocoa isn't, generally speaking, exception-safe.


--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Catch exception in NSArrayController

2009-09-17 Thread Konrad Windszus
I am throwing it myself (or more exactly a c++ library I call within a  
get method of the model class). But I don't want to handle the  
exception in the model class, but rather in the controller, which can  
then disable some UI buttons.


Am 17.09.2009 um 16:41 schrieb Sean McBride:


On 9/17/09 1:26 PM, Konrad Windszus said:


I have a classical binding usecase: A NSArrayController is used for
displaying the columns of a NSTableView. The columns itself therefore
use the arrangedObject method of the NSArrayController. In the get
methods of the model itself (which normally return an NSString* which
should be displayed in the column), there could occur an exception. I
want to catch that exception in the NSArrayController. I therefore
subclassed the NSArrayController and overwrote valueForKeyPath with a
simple:

- (id)valueForKeyPath:(NSString *)keyPath {
try {
[super valueForKeyPath:keyPath];
}
catch (...) {
// want to get here, if there is an exception thrown within the
model class
}
}

Unfortunately it is only called with arrangedObjects. At that point  
no

exception is thrown yet. Somewhere after that a valueForKeyPath must
be executed on that returned arrangedObjects. Since I have not
subclassed this proxy class, I cannot intercept its valueForKeyPath
method and therefore cannot catch the exception. Is there a simple  
way

to catch exceptions in the controller class which is thrown during
calling a get method (over binding mechanims)?


What's this exception you speak of?  Are you throwing or is the  
system?


--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Catch exception in NSArrayController

2009-09-17 Thread Kyle Sluder

On Sep 17, 2009, at 8:27 AM, Konrad Windszus konra...@gmx.de wrote:

I am throwing it myself (or more exactly a c++ library I call within  
a get method of the model class). But I don't want to handle the  
exception in the model class, but rather in the controller, which  
can then disable some UI buttons.


This isn't safe. You will need to wrap that class in an Objective-C  
class that converts the exception into some other means of signifying  
to the controller layer that it should disable the UI.


--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com