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:
parent
b73c31c725
commit
50ee03e3f0
8 changed files with 25 additions and 19 deletions
|
|
@ -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) {
|
inline string line_context(const string& line, istream_pos_type pos) {
|
||||||
std::ostringstream buf;
|
std::ostringstream buf;
|
||||||
buf << " " << line << std::endl << " ";
|
buf << " " << line << " ";
|
||||||
istream_pos_type idx = (pos == istream_pos_type(0) ?
|
istream_pos_type idx = (pos == istream_pos_type(0) ?
|
||||||
istream_pos_type(line.length()) : pos);
|
istream_pos_type(line.length()) : pos);
|
||||||
idx -= 1;
|
idx -= 1;
|
||||||
|
|
|
||||||
|
|
@ -96,13 +96,14 @@ void expr_t::parse(const string& _str, const unsigned int flags)
|
||||||
compiled = false;
|
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())
|
if (! parser.get())
|
||||||
throw_(parse_error, "Value expression parser not initialized");
|
throw_(parse_error, "Value expression parser not initialized");
|
||||||
|
|
||||||
str = "<stream>";
|
str = "<stream>";
|
||||||
ptr = parser->parse(in, flags);
|
ptr = parser->parse(in, flags, original_string);
|
||||||
compiled = false;
|
compiled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse(const string& _str, const unsigned int flags = 0);
|
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);
|
void compile(scope_t& scope);
|
||||||
value_t calc(scope_t& scope);
|
value_t calc(scope_t& scope);
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ void calc_xacts::operator()(xact_t& xact)
|
||||||
#if 0
|
#if 0
|
||||||
add_error_context(xact_context(xact));
|
add_error_context(xact_context(xact));
|
||||||
#endif
|
#endif
|
||||||
throw err;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ namespace {
|
||||||
(string(" (-") + opt->short_opt + "):") :
|
(string(" (-") + opt->short_opt + "):") :
|
||||||
": "));
|
": "));
|
||||||
#endif
|
#endif
|
||||||
throw err;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ void process_environment(const char ** envp, const string& tag,
|
||||||
catch (const std::exception& err) {
|
catch (const std::exception& err) {
|
||||||
add_error_context("While parsing environment variable option '"
|
add_error_context("While parsing environment variable option '"
|
||||||
<< *p << "':");
|
<< *p << "':");
|
||||||
throw err;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -385,7 +385,8 @@ expr_t::parser_t::parse_value_expr(std::istream& in,
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t::ptr_op_t
|
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 {
|
try {
|
||||||
ptr_op_t top_node = parse_value_expr(in, flags);
|
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;
|
return top_node;
|
||||||
}
|
}
|
||||||
catch (const std::exception& err) {
|
catch (const std::exception& err) {
|
||||||
add_error_context("While parsing value expression:\n");
|
add_error_context("While parsing value expression:");
|
||||||
#if 0
|
if (original_string) {
|
||||||
add_error_context(line_context(str, in.tellg() - 1));
|
istream_pos_type pos = in.tellg();
|
||||||
#endif
|
pos -= 1;
|
||||||
throw err;
|
add_error_context(line_context(*original_string, pos));
|
||||||
|
}
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,11 @@ public:
|
||||||
TRACE_DTOR(parser_t);
|
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) {
|
ptr_op_t parse(string& str, const flags_t flags = EXPR_PARSE_NORMAL) {
|
||||||
std::istringstream stream(str);
|
std::istringstream stream(str);
|
||||||
return parse(stream, flags);
|
return parse(stream, flags, &str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ xact_t * parse_xact(char * line, account_t * account, entry_t * entry = NULL)
|
||||||
}
|
}
|
||||||
catch (const std::exception& err) {
|
catch (const std::exception& err) {
|
||||||
add_error_context("While parsing transaction amount:\n");
|
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) {
|
catch (const std::exception& err) {
|
||||||
add_error_context("While parsing transaction cost:\n");
|
add_error_context("While parsing transaction cost:\n");
|
||||||
throw err;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xact->cost->sign() < 0)
|
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) {
|
catch (const std::exception& err) {
|
||||||
add_error_context("While parsing assigned balance:\n");
|
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) {
|
catch (const std::exception& err) {
|
||||||
add_error_context("While parsing transaction:\n");
|
add_error_context("While parsing transaction:\n");
|
||||||
add_error_context(line_context(line, in.tellg()));
|
add_error_context(line_context(line, in.tellg()));
|
||||||
throw err;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue