REALCallFunctionWithExceptionHandler example?

Hi,
has anyone tried REALCallFunctionWithExceptionHandler and found use for it?

Greetings
Christian

I have not, I suspect you will have to be the first of us to enter this unknown territory.

Probably for testing it might be wise to create a function in Xojo that just always throws, and then call that one and see what happens.

[quote=214758:@Christian Schmitz]Hi,
has anyone tried REALCallFunctionWithExceptionHandler and found use for it?

Greetings
Christian[/quote]

Yeah,

something like

struct delegateMessage {
    REALobject memblock;
    RBInteger size;
    REALstring msg;
};

typedef void (*DelegateTaskProc)(void *data);
void Test_MemoryBlock_allocation(void* myData)
{
    delegateMessage* myStuff = (delegateMessage*)myData;
    XMemoryBlock xm(myStuff->size);     //Note that XString and XMemoryBlock  represent classes using Dynamic access. 
    myStuff->memblock = (REALobject)xm;
    XString xs;                //Note that XString and XMemoryBlock  represent classes using Dynamic access. 
    if (myStuff->memblock) {
        xs = "got the memoryblock";
    } else xs = "failure to get a memoryblock";
    myStuff->msg = (REALstring)xs;
}

REALobject Perform_Creation_of_Object_with_exception_handler(DelegateTaskProc proc, RBInteger size)
{
    delegateMessage myDelegate;
    myDelegate.memblock = NULL;
    myDelegate.size = size;
    myDelegate.msg = NULL;
    
    REALobject myObject = REALCallFunctionWithExceptionHandler(proc, &myDelegate);
    if (myObject) {
        LOG("EXCEPTION!!!!!!!!!!!!!!!");
        REALRaiseException(myObject);
        //REALUnlockObject(myObject);
    }
    XString xs = myDelegate.msg;
    
    return myDelegate.memblock;
}

Then create a method like:

REALobject Test_Memblock( RBInteger size)
{
return Perform_Creation_of_Object_with_exception_handler(Test_MemoryBlock_allocation, size);
}

As far as I see it still stops in debugger here showing the exception.
so it does not ignore it.

You ignore it by unlocking the exception object. You don’t raise it.

but it’s raised anyway.

That’s not true.

But IDE stopped for me at the line like a regular exception!?

Oh yeah, turn off break on exception. Good catch.

[quote=214908:@Alfred Van Hoek] REALobject myObject = REALCallFunctionWithExceptionHandler(proc, &myDelegate); if (myObject) { LOG("EXCEPTION!!!!!!!!!!!!!!!"); REALRaiseException(myObject); //REALUnlockObject(myObject); }[/quote]

Isn’t the exception then not raising in the IDE? Just were reading source code but I don’t understand well if it raises or not. Language barrier…

Thanks!

When Break on exceptions is turned off, and the plugin is not going to raise the exception, just dismissing it by the Unlock, then there won’t be an exception; the memory block returned will be nil, because there is no sufficient memory. The plugin SDK provides a deprecated REALNewMemoryBlock call, that under the same circumstances (low memory) will return a nil memblock. The difference between the two is when you set Break on exceptions. With REALNewMemoryBlock there is no exception, as Christian pointed out, but the new way of creating a memblock by the plugin will trigger the exception, despite the attempt to ignore the exception.

Whether this is good or bad is a matter of taste, I think. But the point is that the deprecated call cannot be completely replaced by dynamic access.

Thanks a lot @Alfred Van Hoek! Crystal clear message. Really appreciated. :slight_smile: