Re: Correct way to throw exceptions/errors from C to ST

Holger Hans Peter Freyther <[email protected]>
Newsgroups gmane.comp.lang.smalltalk.gnu.general
Message-ID <[email protected]>
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-    ]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.