Replacing a StandardToolSet

Tom Phoenix rootbeer at redcat.com
Wed Feb 6 17:49:45 UTC 2008


On Feb 6, 2008 12:21 AM, Igor Stasenko <siguctua at gmail.com> wrote:

> i'm stuck with a code to handle errors in squeak image.
> I want to replace the default behavior, when unhandled error occurs is
> to same as user pressing 'Abort' button.
>
> This is a code snippet, how i doing this:
>
> ----
> HydraDebugToolSet>>debugError: anError
>         recursed == true ifTrue: [ ^ Processor terminateActive ].
>         recursed := true.
>
>         Transcript show: 'Error in interpreter (', HydraVM
> myInterpreterInstance asString , ')',
>                 String cr,
>                 anError description,
>                 String cr,
>                 anError signalerContext shortStack.
>
>         Smalltalk
>                 logError: anError description
>                 inContext: anError signalerContext
>                 to: 'HydraDebug.log'.
>
>         recursed := false.
>         Processor terminateActive.
>         ^ nil

There's something about that variable 'recursed' that smells wrong. I
think it's that you're trying to make your code reentrant, but you're
not testing and setting that flag atomically. Maybe you need to use a
Semaphore?

> The problem in doing Processor terminateActive - i'm not sure if this
> works exactly as abandoning process.
> And i'm stuck, because if i don't put Processor terminateActive, then
> it starts an infinite loop barfing on sending unknown message to nil
> (i suspect that it's because i returning nil at exit).

Exactly; you need to make a method that, unlike any normal method,
never returns. Part of the trouble is that sometimes the current
process is the UI process, which needs to be replaced before it's
terminated. I think you need to end your method with something like
this:

    Project spawnNewProcessIfThisIsUI: Processor activeProcess.
    Processor terminateActive.  "stop here"
    ^self error: 'This line should never be reached.'.

I'm not completely sure whether that is the Right Thing to Do in all
circumstances, especially under the Hydra VM. Does that work for you?
Good luck with it!

--Tom Phoenix



More information about the Squeak-dev mailing list