summaryrefslogtreecommitdiff
path: root/main.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-12 20:57:44 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-12 20:57:44 -0400
commitb20ddba1d5652157bb432e0c826ea746dd81482e (patch)
treebdbd90c64e278ada11d36bbbbfd9022f350172ac /main.cc
parent0f2ed1f5e36c8e76bc4fc6c406e7d921f794df6a (diff)
downloadfork-ledger-b20ddba1d5652157bb432e0c826ea746dd81482e.tar.gz
fork-ledger-b20ddba1d5652157bb432e0c826ea746dd81482e.tar.bz2
fork-ledger-b20ddba1d5652157bb432e0c826ea746dd81482e.zip
added error checking
Diffstat (limited to 'main.cc')
-rw-r--r--main.cc40
1 files changed, 36 insertions, 4 deletions
diff --git a/main.cc b/main.cc
index 5b4de2f0..661feb25 100644
--- a/main.cc
+++ b/main.cc
@@ -581,13 +581,45 @@ int main(int argc, char * argv[])
// Compile the sorting string
- if (! sort_string.empty())
- sort_order.reset(parse_value_expr(sort_string));
+ if (! sort_string.empty()) {
+ try {
+ std::istringstream stream(sort_string);
+ sort_order.reset(parse_value_expr(stream));
+ if (! stream.eof()) {
+ std::ostringstream err;
+ err << "Unexpected character '" << char(stream.peek()) << "'";
+ throw value_expr_error(err.str());
+ }
+ else if (! sort_order.get()) {
+ std::cerr << "Failed to parse sort criteria!" << std::endl;
+ return 1;
+ }
+ }
+ catch (const value_expr_error& err) {
+ std::cerr << "Error in sort criteria: " << err.what() << std::endl;
+ return 1;
+ }
+ }
// Setup the meaning of %t and %T, used in format strings
- format_t::value_expr.reset(parse_value_expr(value_expr));
- format_t::total_expr.reset(parse_value_expr(total_expr));
+ try {
+ format_t::value_expr.reset(parse_value_expr(value_expr));
+ }
+ catch (const value_expr_error& err) {
+ std::cerr << "Error in amount (-t) specifier: " << err.what()
+ << std::endl;
+ return 1;
+ }
+
+ try {
+ format_t::total_expr.reset(parse_value_expr(total_expr));
+ }
+ catch (const value_expr_error& err) {
+ std::cerr << "Error in total (-T) specifier: " << err.what()
+ << std::endl;
+ return 1;
+ }
// Now handle the command that was identified above.