This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with primitive-throw?


> When I try to compile this piece of code:
> 
> (try-catch
>     (begin
>       (format (current-error-port) "Testing ...~%")
>       (primitive-throw (make <java.lang.RuntimeException> "test")))
>   (exc <java.lang.Throwable>
>        (format (current-error-port) "an error occurred!~%")))
> 
> I get the following error:

A work around is to throw the exception in a separate function:

  % cat Foo.scm

  (define (throw-error)
    (primitive-throw (make <java.lang.RuntimeException> "test")))

  (define (foo)
    (try-catch
     (begin
       (format (current-error-port) "Testing ...~%")
       (throw-error))
     (exc <java.lang.Throwable>
          (format (current-error-port) "an error occurred!~%"))))

  (foo)

  % java kawa.repl --main -C Foo.scm
  (compiling Foo.scm)
  % java Foo
  Testing ...
  an error occurred!


Regards,
Chris Dean


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]