catching bad alloc
This commit is contained in:
parent
829c70d320
commit
7f2a212c6a
@ -119,48 +119,52 @@ void Concordia::loadRAMIndexFromDisk() {
|
||||
if (boost::filesystem::exists(_getWordMapFilePath())
|
||||
&& boost::filesystem::exists(_getHashedIndexFilePath())
|
||||
&& boost::filesystem::exists(_getMarkersFilePath())) {
|
||||
// reading index from file
|
||||
_T->clear();
|
||||
std::ifstream hashedIndexFile;
|
||||
hashedIndexFile.open(
|
||||
_getHashedIndexFilePath().c_str(), std::ios::in
|
||||
| std::ios::ate | std::ios::binary);
|
||||
saidx_t hiFileSize = hashedIndexFile.tellg();
|
||||
if (hiFileSize > 0) {
|
||||
hashedIndexFile.seekg(0, std::ios::beg);
|
||||
try {
|
||||
// reading index from file
|
||||
_T->clear();
|
||||
std::ifstream hashedIndexFile;
|
||||
hashedIndexFile.open(
|
||||
_getHashedIndexFilePath().c_str(), std::ios::in
|
||||
| std::ios::ate | std::ios::binary);
|
||||
long hiFileSize = hashedIndexFile.tellg();
|
||||
if (hiFileSize > 0) {
|
||||
hashedIndexFile.seekg(0, std::ios::beg);
|
||||
|
||||
while (!hashedIndexFile.eof()) {
|
||||
INDEX_CHARACTER_TYPE character =
|
||||
Utils::readIndexCharacter(hashedIndexFile);
|
||||
Utils::appendCharToSaucharVector(_T, character);
|
||||
while (!hashedIndexFile.eof()) {
|
||||
INDEX_CHARACTER_TYPE character =
|
||||
Utils::readIndexCharacter(hashedIndexFile);
|
||||
Utils::appendCharToSaucharVector(_T, character);
|
||||
}
|
||||
hashedIndexFile.close();
|
||||
} else {
|
||||
hashedIndexFile.close();
|
||||
throw ConcordiaException("Index corrupt: empty hash index file");
|
||||
}
|
||||
hashedIndexFile.close();
|
||||
} else {
|
||||
hashedIndexFile.close();
|
||||
throw ConcordiaException("Index corrupt: empty hash index file");
|
||||
}
|
||||
|
||||
// reading markers from file
|
||||
_markers->clear();
|
||||
std::ifstream markersFile;
|
||||
markersFile.open(_getMarkersFilePath().c_str(), std::ios::in
|
||||
| std::ios::ate | std::ios::binary);
|
||||
long maFileSize = markersFile.tellg();
|
||||
if (maFileSize > 0) {
|
||||
markersFile.seekg(0, std::ios::beg);
|
||||
// reading markers from file
|
||||
_markers->clear();
|
||||
std::ifstream markersFile;
|
||||
markersFile.open(_getMarkersFilePath().c_str(), std::ios::in
|
||||
| std::ios::ate | std::ios::binary);
|
||||
long maFileSize = markersFile.tellg();
|
||||
if (maFileSize > 0) {
|
||||
markersFile.seekg(0, std::ios::beg);
|
||||
|
||||
while (!markersFile.eof()) {
|
||||
SUFFIX_MARKER_TYPE marker =
|
||||
Utils::readMarker(markersFile);
|
||||
_markers->push_back(marker);
|
||||
while (!markersFile.eof()) {
|
||||
SUFFIX_MARKER_TYPE marker =
|
||||
Utils::readMarker(markersFile);
|
||||
_markers->push_back(marker);
|
||||
}
|
||||
markersFile.close();
|
||||
} else {
|
||||
markersFile.close();
|
||||
throw ConcordiaException("Index corrupt: empty markers file");
|
||||
}
|
||||
markersFile.close();
|
||||
} else {
|
||||
markersFile.close();
|
||||
throw ConcordiaException("Index corrupt: empty markers file");
|
||||
// generating suffix array
|
||||
_SA = _index->generateSuffixArray(_T);
|
||||
} catch (const std::bad_alloc&) {
|
||||
throw ConcordiaException("Error allocating memory, probably out of memory.");
|
||||
}
|
||||
// generating suffix array
|
||||
_SA = _index->generateSuffixArray(_T);
|
||||
} else {
|
||||
throw ConcordiaException("Index corrupt: missing files");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user