• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC error messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC error messages


  • Subject: Re: ObjC error messages
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Mon, 18 Feb 2002 12:55:20 -0500

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Monday, February 18, 2002, at 04:04 , Malte Tancred wrote:

On thursday, february 14, 2002, at 04:10 , Marcel Weiher wrote:
I agree that some sort of logging should occurr if the exception
isn't handled.

DNU isn't an exception. It is a message that is sent by the runtime whose default implementation just happens to raise an exception, just like it also happens to log an error.

But I still argue that it should be handled the way
all other uncaught exceptions are handled, ie through the top level
execption handler.

DNU isn't an exception, it is a message sent by the runtime whose default implementation raises an exception. It would be a different issues if the runtime actually raised an exception. It doesn't.

Exceptions in Objective-C are an add-on that is not part of the basic runtime.

I begin to see what I was actually missing. :-)

However, it still feels a bit awkward. Please help me understand.

As far as I can see, the default mechanism in Obj-C (from the darwin source, ie no Foundation, no exceptions) for unrecognized messages is to log the error and then abort() the program.

In Foundation exceptions are introduced as a means of handling program inconsistencies at a higher level.

How come, from the point of view of the runtime, an unrecognized message isn't treated as such? Ie, it doesn't crash the program anymore, but instead transforms the error to a higher order exception, for callers to handle?

Exactly. Your object decides how to handle the message.
...
Exactly, if you decide to handle the message that is sent, then it won't even raise an exception. For example, Higher Order Messaging uses DNU-handling (forwardInvocation:, to be precise) in its implementation. So does NSProxy.
...
Yes, you can send different messages in your DNU handler, or none. You can also log messages or even raise an exception.

My 'problem' was that I was writing the class sending the message in the first place. As I could catch an exception and thereby handle the situation, I wondered why this logging occurred in the first place.

You can always do something like this:

if( [ object respondsToSelector: @selector( myMethodSelector ) ] )
[ object myMethodSelector ];
else
NSLog( @"%@", @"Oops, object doesn't understand that myMethodSelector" );



- --
Clark S. Cox, III
email@hidden
http://www.whereismyhead.com/clark/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (Darwin)
Comment: For info see http://www.gnupg.org

iD8DBQE8cUAOd6STocYT1xURAlK2AJ9FymAtfSreZKY1rKdT0ciE0D9VWQCdEgm7
pNOOWQ7AtZbYGId3Be+bMnM=
=Hi5Y
-----END PGP SIGNATURE-----
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: ObjC error messages (From: Malte Tancred <email@hidden>)

  • Prev by Date: Re: PB Save As ASCII?
  • Next by Date: Re: Toolbar icons
  • Previous by thread: Re: ObjC error messages
  • Next by thread: avoid initWithURL?
  • Index(es):
    • Date
    • Thread