From cfd7ffb12645c198a5b15891654f6ad6a0e4db27 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 1 Mar 2012 22:20:38 -0600 Subject: Provide more context if a valexpr function call fails --- src/op.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/op.cc') diff --git a/src/op.cc b/src/op.cc index 372101f0..8e9df812 100644 --- a/src/op.cc +++ b/src/op.cc @@ -272,10 +272,16 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth) if (has_right()) call_args.set_args(split_cons_expr(right())); - if (func->is_function()) - result = func->as_function()(call_args); - else - result = func->calc(call_args, locus, depth + 1); + try { + if (func->is_function()) + result = func->as_function()(call_args); + else + result = func->calc(call_args, locus, depth + 1); + } + catch (const std::exception&) { + add_error_context(_("While calling function '%1':" << name)); + throw; + } check_type_context(scope, result); break; @@ -308,7 +314,8 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth) if (args_index < args_count) throw_(calc_error, - _("Too few arguments in function call (saw %1)") << args_count); + _("Too few arguments in function call (saw %1, wanted %2)") + << args_count << args_index); result = right()->calc(call_scope, locus, depth + 1); break; -- cgit v1.2.3