Some more unhandled exceptions

This commit is contained in:
Abs62 2013-09-24 17:56:47 +04:00
parent 1a8bb0ae10
commit 4a414adfdc
9 changed files with 141 additions and 113 deletions

View file

@ -404,6 +404,11 @@ void AardDictionary::loadArticle( quint32 address,
articleBody.resize( articleSize );
df.read( &articleBody.front(), articleSize );
}
catch( std::exception &ex )
{
qWarning( "AARD: Failed loading article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
break;
}
catch(...)
{
break;

3
bgl.cc
View file

@ -746,8 +746,9 @@ void BglArticleRequest::run()
articlesIncluded.insert( chain[ x ].articleOffset );
} // try
catch( Utf8::exCantDecode )
catch( std::exception &ex )
{
qWarning( "BGL: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
}
}

120
dsl.cc
View file

@ -1238,60 +1238,70 @@ void DslArticleRequest::run()
wstring articleBody;
unsigned headwordIndex;
dict.loadArticle( chain[ x ].articleOffset, wordCaseFolded, tildeValue,
displayedHeadword, headwordIndex, articleBody );
if ( !articlesIncluded.insert( std::make_pair( chain[ x ].articleOffset,
headwordIndex ) ).second )
continue; // We already have this article in the body.
dict.articleNom += 1;
if( displayedHeadword.empty() || isDslWs( displayedHeadword[ 0 ] ) )
displayedHeadword = word; // Special case - insided card
string articleText, articleAfter;
articleText += "<span class=\"dsl_article\">";
articleText += "<div class=\"dsl_headwords\"";
if( dict.isFromLanguageRTL() )
articleText += " dir=\"rtl\"";
articleText += ">";
if( displayedHeadword.size() == 1 && displayedHeadword[0] == '<' ) // Fix special case - "<" header
articleText += "<"; // dslToHtml can't handle it correctly.
else
articleText += dict.dslToHtml( displayedHeadword );
/// After this may be expand button will be inserted
articleAfter += "</div>";
expandTildes( articleBody, tildeValue );
articleAfter += "<div class=\"dsl_definition\"";
if( dict.isToLanguageRTL() )
articleAfter += " dir=\"rtl\"";
articleAfter += ">";
articleAfter += dict.dslToHtml( articleBody );
articleAfter += "</div>";
articleAfter += "</span>";
if( dict.hasHiddenZones() )
try
{
string prefix = "O" + dict.getId().substr( 0, 7 ) + "_" + QString::number( dict.articleNom ).toStdString();
string id1 = prefix + "_expand";
string id2 = prefix + "_opt_";
string button = "<img src=\"qrcx://localhost/icons/expand_opt.png\" class=\"hidden_expand_opt\" id=\"" + id1 +
"\" onclick=\"gdExpandOptPart('" + id1 + "','" + id2 +"')\" alt=\"[+]\"/>";
if( articleText.compare( articleText.size() - 4, 4, "</p>" ) == 0 )
articleText.insert( articleText.size() - 4, " " + button );
else
articleText += button;
}
dict.loadArticle( chain[ x ].articleOffset, wordCaseFolded, tildeValue,
displayedHeadword, headwordIndex, articleBody );
articleText += articleAfter;
if ( !articlesIncluded.insert( std::make_pair( chain[ x ].articleOffset,
headwordIndex ) ).second )
continue; // We already have this article in the body.
dict.articleNom += 1;
if( displayedHeadword.empty() || isDslWs( displayedHeadword[ 0 ] ) )
displayedHeadword = word; // Special case - insided card
articleText += "<span class=\"dsl_article\">";
articleText += "<div class=\"dsl_headwords\"";
if( dict.isFromLanguageRTL() )
articleText += " dir=\"rtl\"";
articleText += ">";
if( displayedHeadword.size() == 1 && displayedHeadword[0] == '<' ) // Fix special case - "<" header
articleText += "<"; // dslToHtml can't handle it correctly.
else
articleText += dict.dslToHtml( displayedHeadword );
/// After this may be expand button will be inserted
articleAfter += "</div>";
expandTildes( articleBody, tildeValue );
articleAfter += "<div class=\"dsl_definition\"";
if( dict.isToLanguageRTL() )
articleAfter += " dir=\"rtl\"";
articleAfter += ">";
articleAfter += dict.dslToHtml( articleBody );
articleAfter += "</div>";
articleAfter += "</span>";
if( dict.hasHiddenZones() )
{
string prefix = "O" + dict.getId().substr( 0, 7 ) + "_" + QString::number( dict.articleNom ).toStdString();
string id1 = prefix + "_expand";
string id2 = prefix + "_opt_";
string button = "<img src=\"qrcx://localhost/icons/expand_opt.png\" class=\"hidden_expand_opt\" id=\"" + id1 +
"\" onclick=\"gdExpandOptPart('" + id1 + "','" + id2 +"')\" alt=\"[+]\"/>";
if( articleText.compare( articleText.size() - 4, 4, "</p>" ) == 0 )
articleText.insert( articleText.size() - 4, " " + button );
else
articleText += button;
}
articleText += articleAfter;
}
catch( std::exception &ex )
{
qWarning( "DSL: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
articleText = string( "<span class=\"dsl_article\">" )
+ string( QObject::tr( "Article loading error" ).toUtf8().constData() )
+ "</span>";
}
Mutex::Lock _( dataMutex );
@ -1472,13 +1482,11 @@ void DslResourceRequest::run()
hasAnyData = true;
}
catch( File::Ex & )
catch( std::exception &ex )
{
// No such resource -- we don't set the hasAnyData flag then
}
catch( Utf8::exCantDecode )
{
// Failed to decode some utf8 -- probably the resource name is no good
qWarning( "DSL: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), dict.getName().c_str(), ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then
}
finish();

View file

@ -283,6 +283,10 @@ void HunspellArticleRequest::run()
{
qWarning( "Hunspell: charset convertion error, no processing's done: %s\n", e.what() );
}
catch( std::exception & e )
{
qWarning( "Hunspell: error: %s\n", e.what() );
}
if ( suggestions )
{

View file

@ -17,7 +17,7 @@ public:
DEF_EX( Ex, "Iconv exception", std::exception )
DEF_EX_STR( exCantInit, "Can't initialize iconv conversion:", Ex )
DEF_EX( exIncorrectSeq, "Invalid character sequence encountered during character convesion", Ex )
DEF_EX( exIncorrectSeq, "Invalid character sequence encountered during character conversion", Ex )
DEF_EX( exPrematureEnd, "Character sequence ended prematurely during character conversion", Ex )
DEF_EX_STR( exOther, "An error has occured during character conversion:", Ex )

View file

@ -464,25 +464,33 @@ void SdictArticleRequest::run()
string headword, articleText;
headword = chain[ x ].word;
dict.loadArticle( chain[ x ].articleOffset, articleText );
// Ok. Now, does it go to main articles, or to alternate ones? We list
// main ones first, and alternates after.
try
{
dict.loadArticle( chain[ x ].articleOffset, articleText );
// We do the case-folded comparison here.
// Ok. Now, does it go to main articles, or to alternate ones? We list
// main ones first, and alternates after.
wstring headwordStripped =
Folding::applySimpleCaseOnly( Utf8::decode( headword ) );
// We do the case-folded comparison here.
multimap< wstring, pair< string, string > > & mapToUse =
( wordCaseFolded == headwordStripped ) ?
mainArticles : alternateArticles;
wstring headwordStripped =
Folding::applySimpleCaseOnly( Utf8::decode( headword ) );
mapToUse.insert( pair< wstring, pair< string, string > >(
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
pair< string, string >( headword, articleText ) ) );
multimap< wstring, pair< string, string > > & mapToUse =
( wordCaseFolded == headwordStripped ) ?
mainArticles : alternateArticles;
articlesIncluded.insert( chain[ x ].articleOffset );
mapToUse.insert( pair< wstring, pair< string, string > >(
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
pair< string, string >( headword, articleText ) ) );
articlesIncluded.insert( chain[ x ].articleOffset );
}
catch( std::exception &ex )
{
qWarning( "SDict: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
}
}
if ( mainArticles.empty() && alternateArticles.empty() )

View file

@ -396,7 +396,7 @@ void StardictDictionary::loadArticle( uint32_t address,
else
if ( !size )
{
FDPRINTF( stderr, "Warning: short entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: short entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -410,7 +410,7 @@ void StardictDictionary::loadArticle( uint32_t address,
if ( size < entrySize )
{
FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -431,7 +431,7 @@ void StardictDictionary::loadArticle( uint32_t address,
{
if ( size < sizeof( uint32_t ) )
{
FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -445,7 +445,7 @@ void StardictDictionary::loadArticle( uint32_t address,
if ( size < entrySize )
{
FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -456,8 +456,8 @@ void StardictDictionary::loadArticle( uint32_t address,
}
else
{
FDPRINTF( stderr, "Warning: non-alpha entry type 0x%x for the word %s encountered.\n",
type, headword.c_str() );
qWarning( "Stardict: non-alpha entry type 0x%x for the word %s encountered in \"%s\".\n",
type, headword.c_str(), getName().c_str() );
break;
}
}
@ -474,7 +474,7 @@ void StardictDictionary::loadArticle( uint32_t address,
if ( size < len + 2 )
{
FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -489,7 +489,7 @@ void StardictDictionary::loadArticle( uint32_t address,
// An entry which havs its size before contents
if ( size < sizeof( uint32_t ) + 1 )
{
FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -501,7 +501,7 @@ void StardictDictionary::loadArticle( uint32_t address,
if ( size < sizeof( uint32_t ) + 1 + entrySize )
{
FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() );
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n", headword.c_str(), getName().c_str() );
break;
}
@ -512,8 +512,8 @@ void StardictDictionary::loadArticle( uint32_t address,
}
else
{
FDPRINTF( stderr, "Warning: non-alpha entry type 0x%x for the word %s encountered.\n",
(unsigned)*ptr, headword.c_str() );
qWarning( "Stardict: non-alpha entry type 0x%x for the word %s encountered in \"%s\".\n",
(unsigned)*ptr, headword.c_str(), getName().c_str() );
break;
}
}
@ -1115,13 +1115,11 @@ void StardictResourceRequest::run()
hasAnyData = true;
}
catch( File::Ex & )
catch( std::exception &ex )
{
// No such resource -- we don't set the hasAnyData flag then
}
catch( Utf8::exCantDecode )
{
// Failed to decode some utf8 -- probably the resource name is no good
qWarning( "Stardict: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), dict.getName().c_str(), ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then
}
catch( ... )
{

44
xdxf.cc
View file

@ -443,25 +443,33 @@ void XdxfArticleRequest::run()
string headword, articleText;
headword = chain[ x ].word;
dict.loadArticle( chain[ x ].articleOffset, articleText );
// Ok. Now, does it go to main articles, or to alternate ones? We list
// main ones first, and alternates after.
try
{
dict.loadArticle( chain[ x ].articleOffset, articleText );
// We do the case-folded comparison here.
// Ok. Now, does it go to main articles, or to alternate ones? We list
// main ones first, and alternates after.
wstring headwordStripped =
Folding::applySimpleCaseOnly( Utf8::decode( headword ) );
// We do the case-folded comparison here.
multimap< wstring, pair< string, string > > & mapToUse =
( wordCaseFolded == headwordStripped ) ?
mainArticles : alternateArticles;
wstring headwordStripped =
Folding::applySimpleCaseOnly( Utf8::decode( headword ) );
mapToUse.insert( pair< wstring, pair< string, string > >(
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
pair< string, string >( headword, articleText ) ) );
multimap< wstring, pair< string, string > > & mapToUse =
( wordCaseFolded == headwordStripped ) ?
mainArticles : alternateArticles;
articlesIncluded.insert( chain[ x ].articleOffset );
mapToUse.insert( pair< wstring, pair< string, string > >(
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
pair< string, string >( headword, articleText ) ) );
articlesIncluded.insert( chain[ x ].articleOffset );
}
catch( std::exception &ex )
{
qWarning( "XDXF: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
}
}
if ( mainArticles.empty() && alternateArticles.empty() )
@ -983,13 +991,11 @@ void XdxfResourceRequest::run()
hasAnyData = true;
}
catch( File::Ex & )
catch( std::exception &ex )
{
// No such resource -- we don't set the hasAnyData flag then
}
catch( Utf8::exCantDecode )
{
// Failed to decode some utf8 -- probably the resource name is no good
qWarning( "XDXF: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), dict.getName().c_str(), ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then
}
finish();

10
zim.cc
View file

@ -936,13 +936,11 @@ void ZimResourceRequest::run()
hasAnyData = true;
}
catch( File::Ex & )
catch( std::exception &ex )
{
// No such resource -- we don't set the hasAnyData flag then
}
catch( Utf8::exCantDecode )
{
// Failed to decode some utf8 -- probably the resource name is no good
qWarning( "ZIM: Failed loading resource \"%s\" from \"%s\", reason: %s\n",
resourceName.c_str(), dict.getName().c_str(), ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then
}
finish();