« Return to Thread: What the usage of tryHandle and handle

Re: What the usage of tryHandle and handle

by Feng Feng :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello Lyle,

Thank you for your excellent explanation for what the difference is.

Now, I have one more question related to the usage of the function,

For the code,
sender->handle(this,FXSEL(SEL_COMMAND,ID_HIDE),NULL);

Does it mean the following?

Use sender's handle to deliver the message SEL_COMMAND to object which is created with ID_HIDE.

If
FXMAPFUNC(SEL_COMMAND, XXX::ID_HIDE, XXX::onHide),

Then the function onHide will be called.

Is this correct?

Thank you
Feng













From: Lyle Johnson <lyle@...>
To: Feng Feng <askfoxtoolkit@...>
Sent: Tuesday, June 23, 2009 1:53:07 PM
Subject: Re: [Foxgui-users] What the usage of tryHandle and handle


On Jun 23, 2009, at 1:39 PM, Feng Feng wrote:

What the usage of tryHandle and handle is?

You call either handle() or tryHandle() to send a message to an object. Both methods expect the same arguments. The difference between them has to do with how they deal with exceptions.

The FOX library will raise runtime exceptions under certain conditions when a resource is unavailable. For example, if you're trying to scale an image and FOX isn't able to dynamically allocate the memory it needs to carry out that operation, it will throw an FXMemoryException. All of these resource-related exceptions are subclasses of the FXResourceException base class.

So if you're sening a message to an object using handle(), and if that results in an FXResourceException being thrown, you will need to deal with the exception in your code, e.g.

try {
obj->handle(this, FXSEL(SEL_xxx, message), ptr);
} catch (FXResourceException& ex) {
// handle it!
}

If you instead send the message using tryHandle(), FOX will catch any thrown exceptions for you, and return zero if an exception was thrown:

long result = obj->tryHandle(this, FXSEL(SEL_xxx, message), ptr);
if (result == 0) {
// the message was not handled, or possibly an exception was thrown
}

Hope this helps,

Lyle


------------------------------------------------------------------------------

_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

 « Return to Thread: What the usage of tryHandle and handle