help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Correct way to throw exceptions/errors from C to ST


From: Holger Hans Peter Freyther
Subject: Re: [Help-smalltalk] Correct way to throw exceptions/errors from C to ST
Date: Tue, 7 Apr 2015 19:51:18 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Apr 07, 2015 at 06:24:15PM +0200, Roland Plüss wrote:

> I sure can decide the return type. I just considered it quite quick and
> easy if I could return an #int if I link to a function actually
> returning an integer. I certainly could return nil but then I have no
> idea what error really happened nor can I properly catch it (well...
> besides ifNotNil: ). Since Smalltalk has already an exception/error
> system why not using it? I don't like wrangling a language unless
> there's no other choice.

It is a matter of how much time you have. In most cases I don't
think we want code like:

Smalltalk code...
C-code
C-code
Exception
Smalltalk code...

This will be problematic with native code.. we will do a longjmp
through it or such. So what we can do is that the "next" execution
context can be set once the process returns to Smalltalk. We are
not many but if you want to implement it I am happy to help you.

> 
> And as far as I know I can't include any code into a <primitive>
> declared method.
> 
> I once did the trick with errno type error handling in a module I made
> for Smalltalk but it's cumbersome to use and error prone.

<primitive> will execute the Smalltalk code in case the primtive
failed.  E.g. for the Array

kernel/Array.st-    at: anIndex ifAbsent: aBlock [
kernel/Array.st-        "Answer the index-th indexed instance variable of the 
receiver"
kernel/Array.st-
kernel/Array.st-        <category: 'built ins'>
kernel/Array.st:        <primitive: VMpr_Object_basicAt>
kernel/Array.st-        ^self checkIndexableBounds: anIndex ifAbsent: aBlock
kernel/Array.st-    ]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]