Fixed the way that nested caught exceptions are rethrown, and how value

expressions are displayed when errors are found in them.
This commit is contained in:
John Wiegley 2008-09-15 02:36:50 -04:00
parent b73c31c725
commit 50ee03e3f0
8 changed files with 25 additions and 19 deletions

View file

@ -65,7 +65,7 @@ inline string file_context(const path& file, std::size_t line) {
inline string line_context(const string& line, istream_pos_type pos) {
std::ostringstream buf;
buf << " " << line << std::endl << " ";
buf << " " << line << " ";
istream_pos_type idx = (pos == istream_pos_type(0) ?
istream_pos_type(line.length()) : pos);
idx -= 1;

View file

@ -96,13 +96,14 @@ void expr_t::parse(const string& _str, const unsigned int flags)
compiled = false;
}
void expr_t::parse(std::istream& in, const unsigned int flags)
void expr_t::parse(std::istream& in, const unsigned int flags,
const string * original_string)
{
if (! parser.get())
throw_(parse_error, "Value expression parser not initialized");
str = "<stream>";
ptr = parser->parse(in, flags);
ptr = parser->parse(in, flags, original_string);
compiled = false;
}

View file

@ -96,7 +96,8 @@ public:
}
void parse(const string& _str, const unsigned int flags = 0);
void parse(std::istream& in, const unsigned int flags = 0);
void parse(std::istream& in, const unsigned int flags = 0,
const string * original_string = NULL);
void compile(scope_t& scope);
value_t calc(scope_t& scope);

View file

@ -148,7 +148,7 @@ void calc_xacts::operator()(xact_t& xact)
#if 0
add_error_context(xact_context(xact));
#endif
throw err;
throw;
}
}

View file

@ -93,7 +93,7 @@ namespace {
(string(" (-") + opt->short_opt + "):") :
": "));
#endif
throw err;
throw;
}
}
}
@ -133,7 +133,7 @@ void process_environment(const char ** envp, const string& tag,
catch (const std::exception& err) {
add_error_context("While parsing environment variable option '"
<< *p << "':");
throw err;
throw;
}
}
}

View file

@ -385,7 +385,8 @@ expr_t::parser_t::parse_value_expr(std::istream& in,
}
expr_t::ptr_op_t
expr_t::parser_t::parse(std::istream& in, const flags_t flags)
expr_t::parser_t::parse(std::istream& in, const flags_t flags,
const string * original_string)
{
try {
ptr_op_t top_node = parse_value_expr(in, flags);
@ -399,11 +400,13 @@ expr_t::parser_t::parse(std::istream& in, const flags_t flags)
return top_node;
}
catch (const std::exception& err) {
add_error_context("While parsing value expression:\n");
#if 0
add_error_context(line_context(str, in.tellg() - 1));
#endif
throw err;
add_error_context("While parsing value expression:");
if (original_string) {
istream_pos_type pos = in.tellg();
pos -= 1;
add_error_context(line_context(*original_string, pos));
}
throw;
}
}

View file

@ -92,10 +92,11 @@ public:
TRACE_DTOR(parser_t);
}
ptr_op_t parse(std::istream& in, const flags_t flags = EXPR_PARSE_NORMAL);
ptr_op_t parse(std::istream& in, const flags_t flags = EXPR_PARSE_NORMAL,
const string * original_string = NULL);
ptr_op_t parse(string& str, const flags_t flags = EXPR_PARSE_NORMAL) {
std::istringstream stream(str);
return parse(stream, flags);
return parse(stream, flags, &str);
}
};

View file

@ -223,7 +223,7 @@ xact_t * parse_xact(char * line, account_t * account, entry_t * entry = NULL)
}
catch (const std::exception& err) {
add_error_context("While parsing transaction amount:\n");
throw err;
throw;
}
}
@ -270,7 +270,7 @@ xact_t * parse_xact(char * line, account_t * account, entry_t * entry = NULL)
}
catch (const std::exception& err) {
add_error_context("While parsing transaction cost:\n");
throw err;
throw;
}
if (xact->cost->sign() < 0)
@ -389,7 +389,7 @@ xact_t * parse_xact(char * line, account_t * account, entry_t * entry = NULL)
}
catch (const std::exception& err) {
add_error_context("While parsing assigned balance:\n");
throw err;
throw;
}
}
}
@ -434,7 +434,7 @@ xact_t * parse_xact(char * line, account_t * account, entry_t * entry = NULL)
catch (const std::exception& err) {
add_error_context("While parsing transaction:\n");
add_error_context(line_context(line, in.tellg()));
throw err;
throw;
}
}