Skip to content

Commit

Permalink
Fix the order of the exception arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Dec 23, 2014
1 parent 60f1675 commit 9c507b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions opencog/guile/SchemePrimitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ SCM PrimitiveEnviron::do_call(SCM sfe, SCM arglist)
scm_throw(
scm_from_locale_symbol("C++-EXCEPTION"),
scm_cons(
scm_from_locale_string(msg),
scm_from_locale_string(fe->get_name()),
scm_cons(
scm_from_locale_string(fe->get_name()),
scm_from_locale_string(msg),
SCM_EOL)));
// Hmm. scm_throw never returns.
}
Expand Down
28 changes: 20 additions & 8 deletions tests/scm/SCMPrimitiveUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* tests/scm/SCMPrimitiveUTest.cxxtest
*
* Make sure the scheme primtive extension code works
* Copyright (C) 2009 Linas Vepstas <[email protected]>
* Copyright (C) 2009, 2014 Linas Vepstas <[email protected]>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -66,6 +66,7 @@ class SCMPrimitiveUTest : public CxxTest::TestSuite
void tearDown(void);

void test_H_H(void);
void test_throw(void);
};

// Some example class
Expand Down Expand Up @@ -123,7 +124,7 @@ void SCMPrimitiveUTest::test_H_H(void)

// Create the example class, and define a scheme function,
// named "bingo", that will call one of its methods
MyExampleClass *mtc = new MyExampleClass(as,42);
MyExampleClass *mtc = new MyExampleClass(as, 42);
define_scheme_primitive("bingo", &MyExampleClass::my_func, mtc);

// Now, call bingo, with a reasonable argument. Since
Expand Down Expand Up @@ -151,12 +152,22 @@ void SCMPrimitiveUTest::test_H_H(void)
Handle hn = as->addNode(CONCEPT_NODE, "Hello World!");
TSM_ASSERT ("wrong atom entirely ", hn == nnn);

// ---------------------------------------------------------------
delete mtc;
logger().debug("END TEST: %s", __FUNCTION__);
}

// ============================================================

void SCMPrimitiveUTest::test_throw(void)
{
logger().debug("BEGIN TEST: %s", __FUNCTION__);

// Test the throw of an assertion. This should cause an evaluation
// error. (In the shell, stuff would get printed to terminal)
MyExampleClass *mtc = new MyExampleClass(as, 42);
define_scheme_primitive("whoops", &MyExampleClass::my_other_func, mtc);
std::string trc = eval->eval("(whoops nnn)");
eval_err = eval->eval_error();
bool eval_err = eval->eval_error();
TSM_ASSERT ("Failed to observe exception", eval_err);
printf("Exception trace was: >>%s<<\n", trc.c_str());

Expand All @@ -165,16 +176,16 @@ void SCMPrimitiveUTest::test_H_H(void)
// evaluator.
std::string out = eval->eval(
"(catch #t (lambda () (whoops nnn)) "
" (lambda (key msg name) "
" (lambda (key funcname msg) "
" (display \"caught key=\") "
" (display key) "
" (newline) "
" (display \"caught funcname=\") "
" (display funcname) "
" (newline) "
" (display \"caught msg=\") "
" (display msg) "
" (newline) "
" (display \"caught name=\") "
" (display name) "
" (newline) "
" ))");
eval_err = eval->eval_error();
TSM_ASSERT ("Failed to catch exception", not eval_err);
Expand All @@ -185,6 +196,7 @@ void SCMPrimitiveUTest::test_H_H(void)
strlen("caught key=C++-EXCEPTION"));
TSM_ASSERT ("Wrong exception message", 0 == msg);

delete mtc;
logger().debug("END TEST: %s", __FUNCTION__);
}

Expand Down

0 comments on commit 9c507b7

Please sign in to comment.