paperbox r194 - in trunk: . src
- From: markoa svn gnome org
- To: svn-commits-list gnome org
- Subject: paperbox r194 - in trunk: . src
- Date: Wed, 1 Oct 2008 15:58:37 +0000 (UTC)
Author: markoa
Date: Wed Oct 1 15:58:37 2008
New Revision: 194
URL: http://svn.gnome.org/viewvc/paperbox?rev=194&view=rev
Log:
Catch BadConversion exceptions for bad page and word counts
Modified:
trunk/ChangeLog
trunk/src/document.cc
Modified: trunk/src/document.cc
==============================================================================
--- trunk/src/document.cc (original)
+++ trunk/src/document.cc Wed Oct 1 15:58:37 2008
@@ -24,6 +24,7 @@
#include <algorithm>
#include <functional>
#include <iostream>
+#include <vector>
#include <glibmm/date.h>
#include <glibmm-utils/ustring.h>
#include "document.hh"
@@ -161,7 +162,30 @@
void
Document::set_page_count(const Glib::ustring& page_count)
{
- page_count_ = Glib::Util::convert_to<int>(page_count);
+ try {
+ page_count_ = Glib::Util::convert_to<int>(page_count);
+ } catch (const Glib::Util::BadConversion& ex) {
+ LOG_EXCEPTION("could not convert page count string '"
+ << page_count << "' to an integer.");
+ // In bugs like #552648, this would be the case of trackerd
+ // returned page count string being '119 1', '8 1' etc.
+ // So let's try to split by whitespace and try to convert
+ // whatever is the first token.
+ std::vector<Glib::ustring> tokens = Glib::Util::split(page_count);
+ if (! tokens.size()) {
+ page_count_ = 0;
+ return;
+ }
+
+ try {
+ page_count_ = Glib::Util::convert_to<int>(tokens[0]);
+ LOG_DD("after a split, page count set to " << page_count_);
+ } catch (const Glib::Util::BadConversion& ex) { // give up
+ LOG_EXCEPTION("attempt after splitting by whitespace failed, "
+ << "setting to zero.");
+ page_count_ = 0;
+ }
+ }
}
int
@@ -173,7 +197,14 @@
void
Document::set_word_count(const Glib::ustring& word_count)
{
- word_count_ = Glib::Util::convert_to<int>(word_count);
+ try {
+ word_count_ = Glib::Util::convert_to<int>(word_count);
+ } catch (const Glib::Util::BadConversion& ex) {
+ // no special handling here, as there have been no reports yet
+ LOG_EXCEPTION("could not convert word count string '"
+ << word_count << "' to integer, setting to zero.");
+ word_count_ = 0;
+ }
}
Glib::ustring
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]