* I can't seem to get throw/catch to work
@ 2003-07-30 11:18 Tim Brown
2003-07-30 14:45 ` Peter S. Christopher
0 siblings, 1 reply; 3+ messages in thread
From: Tim Brown @ 2003-07-30 11:18 UTC (permalink / raw)
I'm just starting to get up and running with guile (and scheme).
I'm trying to write a C extension which (eventually) will throw an
exception/error back to guile. I cannot catch an error generated with
scm_throw(). More importantly I can't seem to throw and error within
guile and catch it myself.
guile> (catch #t (throw 'foo) (lambda (key . args) (display key) (newline)))
<unnamed port>:1:11: In procedure gsubr-apply in expression (throw
(quote foo)):
<unnamed port>:1:11: unhandled-exception: foo
ABORT: (misc-error)
Type "(backtrace)" to get more information or "(debug)" to enter the
debugger.
guile>
Ok, so that's me throwing my own error to myself. But I can't even catch
an exception generated by guile.
Neither generally, using the (catch #t ...) nor specifically, using
(catch 'numerical-overflow ...):
guile> (catch #t (/ 1 0) (lambda (key . args) (display key) (newline)))
<unnamed port>:2:11: In procedure / in expression (/ 1 0):
<unnamed port>:2:11: Numerical overflow
ABORT: (numerical-overflow)
guile> (catch 'numerical-overflow (/ 1 0) (lambda (key . args) (display
key) (newline)))
<unnamed port>:3:28: In procedure / in expression (/ 1 0):
<unnamed port>:3:28: Numerical overflow
ABORT: (numerical-overflow)
guile> (version)
"1.6.4"
This happens on linux, solaris and hpux builds, so I assume there's a
problem with my use of the language rather than anything else.
What am I missing here?
Tim
--
Tim Brown <tim.brown@cityc.co.uk> | City Computing Limited |
T: +44 20 8770 2110 | City House, Sutton Park Road |
F: +44 20 8770 2130 | Sutton, Surrey, SM1 2AE, GB |
BEAUTY: What's in your eye when you have a bee in your hand.__________/
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: I can't seem to get throw/catch to work
2003-07-30 11:18 I can't seem to get throw/catch to work Tim Brown
@ 2003-07-30 14:45 ` Peter S. Christopher
0 siblings, 0 replies; 3+ messages in thread
From: Peter S. Christopher @ 2003-07-30 14:45 UTC (permalink / raw)
Cc: guile-user
Hi there,
The second argument to catch must be a thunk (zero
argument procedure). So your first example should be
(catch #t
(lambda () (throw 'foo))
(lambda (key . args) (display key) (newline)))
The way you had it written, the (throw 'foo) was being evaluated before
the catch was fully established.
cheers,
Pete
On Wed, 30 Jul 2003, Tim Brown wrote:
> I'm just starting to get up and running with guile (and scheme).
>
> I'm trying to write a C extension which (eventually) will throw an
> exception/error back to guile. I cannot catch an error generated with
> scm_throw(). More importantly I can't seem to throw and error within
> guile and catch it myself.
>
> guile> (catch #t (throw 'foo) (lambda (key . args) (display key) (newline)))
> <unnamed port>:1:11: In procedure gsubr-apply in expression (throw
> (quote foo)):
> <unnamed port>:1:11: unhandled-exception: foo
> ABORT: (misc-error)
>
> Type "(backtrace)" to get more information or "(debug)" to enter the
> debugger.
> guile>
>
> Ok, so that's me throwing my own error to myself. But I can't even catch
> an exception generated by guile.
>
> Neither generally, using the (catch #t ...) nor specifically, using
> (catch 'numerical-overflow ...):
>
> guile> (catch #t (/ 1 0) (lambda (key . args) (display key) (newline)))
> <unnamed port>:2:11: In procedure / in expression (/ 1 0):
> <unnamed port>:2:11: Numerical overflow
> ABORT: (numerical-overflow)
> guile> (catch 'numerical-overflow (/ 1 0) (lambda (key . args) (display
> key) (newline)))
> <unnamed port>:3:28: In procedure / in expression (/ 1 0):
> <unnamed port>:3:28: Numerical overflow
> ABORT: (numerical-overflow)
> guile> (version)
> "1.6.4"
>
> This happens on linux, solaris and hpux builds, so I assume there's a
> problem with my use of the language rather than anything else.
>
> What am I missing here?
>
> Tim
>
> --
> Tim Brown <tim.brown@cityc.co.uk> | City Computing Limited |
> T: +44 20 8770 2110 | City House, Sutton Park Road |
> F: +44 20 8770 2130 | Sutton, Surrey, SM1 2AE, GB |
> BEAUTY: What's in your eye when you have a bee in your hand.__________/
>
>
>
>
>
> _______________________________________________
> Guile-user mailing list
> Guile-user@gnu.org
> http://mail.gnu.org/mailman/listinfo/guile-user
>
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: I can't seem to get throw/catch to work
@ 2003-07-30 14:22 Dirk Eßer
0 siblings, 0 replies; 3+ messages in thread
From: Dirk Eßer @ 2003-07-30 14:22 UTC (permalink / raw)
Tim Brown <tim.brown@cityc.co.uk> schrieb am 30.07.03 13:25:12:
[ ... ]
> guile> (catch #t (throw 'foo) (lambda (key . args) (display key) (newline)))
> guile> (catch #t (/ 1 0) (lambda (key . args) (display key) (newline)))
AFAIK, catch is not a special form (as it is in CL), but a procedure, which takes
procedures as arguments:
(catch THE-KEY-TO-CATCH BODY-THUNK HANDLER-THUNK)
where
BODY-THUNK is a procedure (lambda () ...), and
HANDLER-THUNK is something like (lambda (key . rest) ...)
So,
(catch #t (lambda () (throw ´foo)) (lambda (key . rest) ...))
(catch #t (lambda () (/ 1 0)) (lambda (key . rest) ...))
should actually do, what you expect.
The mistake in the original examples was, that due to catch being a procedure,
(throw ´foo) and (/ 1 0) are actually evaluated as part of the standard argument
evaluation process, which happens before the actual call; the catch-handler is
installed during execution of BODY-THUNK inside catch. But since evaluating arguments
fails, catch itself is never actually called.
-- dirk
______________________________________________________________________________
Spam-Filter fuer alle - bester Spam-Schutz laut ComputerBild 15-03
WEB.DE FreeMail - Deutschlands beste E-Mail - http://s.web.de/?mc=021120
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-07-30 14:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-30 11:18 I can't seem to get throw/catch to work Tim Brown
2003-07-30 14:45 ` Peter S. Christopher
-- strict thread matches above, loose matches on Subject: below --
2003-07-30 14:22 Dirk Eßer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).