guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

libguile with C++ exceptions


From: Yuk-Wah Wong
Subject: libguile with C++ exceptions
Date: Sun, 18 Mar 2001 13:07:28 +0800

Hi,

I'm trying to use guile as an extension language interpreter in my C++
program, and I'm trying to make the exception handling mechanism of
guile work with that of C++.  Here's what I'm trying to do:

#include <iostream>
#include <guile/gh.h>

class Error { };

SCM body(void* data)
{
  long i = 1;
  int len;
  char* s;
  SCM scm;

  scm = gh_long2scm(i);
  s = gh_scm2newstr(scm, &len);  // bad thing!
  return SCM_UNSPECIFIED;
}

SCM handler(void* data, SCM tag, SCM throw_args)
{
  throw Error();
  return SCM_UNSPECIFIED;
}

void main_prog(int argc, char* argv[])
{
  try {
    gh_catch(SCM_BOOL_T, body, 0, handler, 0);
  } catch (Error e) {
    cerr << "caught" << endl;
  }
  exit(0);
}

int main(int argc, char* argv[])
{
  gh_enter(argc, argv, main_prog);
  return 0;
}

It fails miserably.  No C++ exception is caught, instead the program
is aborted when it tries to run the throw statement.  What's happened
and what should I do?

Thanks heaps for any response.


John




reply via email to

[Prev in Thread] Current Thread [Next in Thread]