diff options
author | John Wiegley <johnw@newartisans.com> | 2008-09-15 02:36:50 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-09-15 02:36:50 -0400 |
commit | 50ee03e3f0a44197722e6c3e85d1f60c48403576 (patch) | |
tree | 17e0c914e8493cb8028b5d02b64cf6f6f2b83b5e /src | |
parent | b73c31c7259ee12bf746f477c9c9919fe72d5394 (diff) | |
download | fork-ledger-50ee03e3f0a44197722e6c3e85d1f60c48403576.tar.gz fork-ledger-50ee03e3f0a44197722e6c3e85d1f60c48403576.tar.bz2 fork-ledger-50ee03e3f0a44197722e6c3e85d1f60c48403576.zip |
Fixed the way that nested caught exceptions are rethrown, and how value
expressions are displayed when errors are found in them.
Diffstat (limited to 'src')
-rw-r--r-- | src/error.h | 2 | ||||
-rw-r--r-- | src/expr.cc | 5 | ||||
-rw-r--r-- | src/expr.h | 3 | ||||
-rw-r--r-- | src/filters.cc | 2 | ||||
-rw-r--r-- | src/option.cc | 4 | ||||
-rw-r--r-- | src/parser.cc | 15 | ||||
-rw-r--r-- | src/parser.h | 5 | ||||
-rw-r--r-- | src/textual.cc | 8 |
8 files changed, 25 insertions, 19 deletions
diff --git a/src/error.h b/src/error.h index 253bcdbf..cfc8b15b 100644 --- a/src/error.h +++ b/src/error.h @@ -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; diff --git a/src/expr.cc b/src/expr.cc index 73bf2993..99319c9b 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -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; } @@ -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); diff --git a/src/filters.cc b/src/filters.cc index 29f517d6..9b5aded4 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -148,7 +148,7 @@ void calc_xacts::operator()(xact_t& xact) #if 0 add_error_context(xact_context(xact)); #endif - throw err; + throw; } } diff --git a/src/option.cc b/src/option.cc index b633de32..6ece64a1 100644 --- a/src/option.cc +++ b/src/option.cc @@ -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; } } } diff --git a/src/parser.cc b/src/parser.cc index eabcb845..0ee66bba 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -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; } } diff --git a/src/parser.h b/src/parser.h index a9828c05..1ad80e82 100644 --- a/src/parser.h +++ b/src/parser.h @@ -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); } }; diff --git a/src/textual.cc b/src/textual.cc index 39b1f55f..e167467f 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -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; } } |