[Pharo-project] Building a run loop that can continue after an unhanded exception
Hi all, I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process. I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception. The code: startRunLoop self stopRunLoop. self runLoop: ( [ [ self doTimedTasks ] on: Exception do: [ :err | " show the exception notifier " ] ] repeatEvery: 0.1 seconds named: 'BrTimeline run loop' ) where repeatEvery:named: is implemented as such: repeatEvery: aDuration named: aProcessName ^ [ [ self value. aDuration asDelay wait ] repeat ] forkNamed: aProcessName Thanks, Joe
On Fri, Sep 7, 2012 at 10:17 AM, Joe Rickerby <joe.rickerby@square-i.net>wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Try with Exception >> #resume
The code:
*startRunLoop* self stopRunLoop. self runLoop: ( [ [ self doTimedTasks ] on: Exception do: [ :err | " show the exception notifier "
err resume
] ] repeatEvery: 0.1 seconds named: 'BrTimeline run loop' )
where repeatEvery:named: is implemented as such:
*repeatEvery:* aDuration *named:* aProcessName ^ [ [ self value. aDuration asDelay wait ] repeat ] forkNamed: aProcessName
Thanks, Joe
-- Mariano http://marianopeck.wordpress.com
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows? Cheers, Henry
On 2012-09-07, at 10:40, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows?
exactly! If you are using 2.0 you can rely on the #debug message [ Error signal: 'Boom' ] on: Error do: [ :error| error debug ]. otherwise simply do Error signal: 'Boom' and you'll get the debugger... If you want to print the stack explicitly try the debugStack: error signalContext printDebugOn: aStream
Not really. Proceed would take me back to where the exception was signalled. I want to resume at the point of the catch of the exception, no matter what happens regarding the exception. On 7 Sep 2012, at 09:40, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows?
Cheers, Henry
I have a solution however! Each timer on the run loop runs its action in a fork. This way any exception raised cannot unroll the stack to outside my run loop code. On 7 Sep 2012, at 12:24, Joe Rickerby <joe.rickerby@squaregroup.co.uk> wrote:
Not really. Proceed would take me back to where the exception was signalled. I want to resume at the point of the catch of the exception, no matter what happens regarding the exception.
On 7 Sep 2012, at 09:40, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows?
Cheers, Henry
On 7 September 2012 12:29, Joe Rickerby <joe.rickerby@square-i.net> wrote:
I have a solution however! Each timer on the run loop runs its action in a fork. This way any exception raised cannot unroll the stack to outside my run loop code.
Right. That's effectively identical to using a delimited continuation: that marks the stack such that when you cut the continuation you can't capture past the stack marker. [1] The problem you might have is that the actions, being forked, run in a separate Process. That means you have to worry about synchronising - accessing common state from two actions (that are, of course, now running in parallel). frank [1] http://okmij.org/ftp/continuations/green-fork.html
On 7 Sep 2012, at 12:24, Joe Rickerby <joe.rickerby@squaregroup.co.uk> wrote:
Not really. Proceed would take me back to where the exception was signalled. I want to resume at the point of the catch of the exception, no matter what happens regarding the exception.
On 7 Sep 2012, at 09:40, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows?
Cheers, Henry
I'm actually doing forkAndWait on the timer actions to prevent any synchronisation problems, and to prevent me spawning too many processes and bringing down the system :/ On 7 Sep 2012, at 13:02, Frank Shearar <frank.shearar@gmail.com> wrote:
On 7 September 2012 12:29, Joe Rickerby <joe.rickerby@square-i.net> wrote:
I have a solution however! Each timer on the run loop runs its action in a fork. This way any exception raised cannot unroll the stack to outside my run loop code.
Right. That's effectively identical to using a delimited continuation: that marks the stack such that when you cut the continuation you can't capture past the stack marker. [1]
The problem you might have is that the actions, being forked, run in a separate Process. That means you have to worry about synchronising - accessing common state from two actions (that are, of course, now running in parallel).
frank
[1] http://okmij.org/ftp/continuations/green-fork.html
On 7 Sep 2012, at 12:24, Joe Rickerby <joe.rickerby@squaregroup.co.uk> wrote:
Not really. Proceed would take me back to where the exception was signalled. I want to resume at the point of the catch of the exception, no matter what happens regarding the exception.
On 7 Sep 2012, at 09:40, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows?
Cheers, Henry
On 7 September 2012 14:27, Joe Rickerby <joe.rickerby@square-i.net> wrote:
I'm actually doing forkAndWait on the timer actions to prevent any synchronisation problems, and to prevent me spawning too many processes and bringing down the system :/
Well, that would work. Have you thought of invoking each action in an [action value] on: Exception do: [:e | "see later"] ? That would prevent any exceptions/errors/notifications at all from breaking the run loop. In the "see later" part you could do tricky things like capture the stack for inspection, via #signalerContext, if I recall correctly. frank
On 7 Sep 2012, at 13:02, Frank Shearar <frank.shearar@gmail.com> wrote:
On 7 September 2012 12:29, Joe Rickerby <joe.rickerby@square-i.net> wrote:
I have a solution however! Each timer on the run loop runs its action in a fork. This way any exception raised cannot unroll the stack to outside my run loop code.
Right. That's effectively identical to using a delimited continuation: that marks the stack such that when you cut the continuation you can't capture past the stack marker. [1]
The problem you might have is that the actions, being forked, run in a separate Process. That means you have to worry about synchronising - accessing common state from two actions (that are, of course, now running in parallel).
frank
[1] http://okmij.org/ftp/continuations/green-fork.html
On 7 Sep 2012, at 12:24, Joe Rickerby <joe.rickerby@squaregroup.co.uk> wrote:
Not really. Proceed would take me back to where the exception was signalled. I want to resume at the point of the catch of the exception, no matter what happens regarding the exception.
On 7 Sep 2012, at 09:40, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
On 07.09.2012 10:17, Joe Rickerby wrote:
Hi all,
I'm having a problem trying to build a run loop. If an exception is signalled within one of the run loop tasks, the exception escapes through the loop and terminates the process.
I know I can catch the exception, and do something like print the message on the Transcript, but I was hoping to build something that was more helpful in development, allowing me to look through the stack, but if I press 'abandon' on that dialog, the run loop would continue from where I caught the exception.
Isn't that exactly what happens if you don't handle the error, and use the proceed button in (pre and normal) debugger windows?
Cheers, Henry
participants (5)
-
Camillo Bruni -
Frank Shearar -
Henrik Sperre Johansen -
Joe Rickerby -
Mariano Martinez Peck