mirror of https://github.com/milvus-io/milvus.git
feat(db): add exception
Former-commit-id: b2a9deb7df0544a303858fff7f4d6eddf3e6b1f7pull/191/head
parent
d744ef4a33
commit
9dcc68b814
|
@ -0,0 +1,54 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
|
* Proprietary and confidential.
|
||||||
|
******************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace zilliz {
|
||||||
|
namespace vecwise {
|
||||||
|
namespace engine {
|
||||||
|
|
||||||
|
class Exception : public std::exception {
|
||||||
|
public:
|
||||||
|
Exception(const std::string& message)
|
||||||
|
: message_(message) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Exception()
|
||||||
|
: message_() {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const char* what() const throw() {
|
||||||
|
if (message_.empty()) {
|
||||||
|
return "Default Exception.";
|
||||||
|
} else {
|
||||||
|
return message_.c_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Exception() throw() {};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
std::string message_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class InvalidArgumentException : public Exception {
|
||||||
|
public:
|
||||||
|
InvalidArgumentException() : Exception("Invalid Argument"){};
|
||||||
|
InvalidArgumentException(const std::string& message) : Exception(message) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
class OutOfRangeException : public Exception {
|
||||||
|
public:
|
||||||
|
OutOfRangeException() : Exception("Out Of Range"){};
|
||||||
|
OutOfRangeException(const std::string& message) : Exception(message) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace engine
|
||||||
|
} // namespace vecwise
|
||||||
|
} // namespace zilliz
|
|
@ -11,6 +11,7 @@
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
#include "Env.h"
|
#include "Env.h"
|
||||||
#include "DBMetaImpl.h"
|
#include "DBMetaImpl.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
namespace zilliz {
|
namespace zilliz {
|
||||||
namespace vecwise {
|
namespace vecwise {
|
||||||
|
@ -46,24 +47,29 @@ void ArchiveConf::ParseCritirias(const std::string& criterias) {
|
||||||
LOG(WARNING) << "Invalid ArchiveConf Criterias: " << token << " Ignore!";
|
LOG(WARNING) << "Invalid ArchiveConf Criterias: " << token << " Ignore!";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto value = std::stoi(kv[1]);
|
try {
|
||||||
criterias_[kv[0]] = value;
|
auto value = std::stoi(kv[1]);
|
||||||
|
criterias_[kv[0]] = value;
|
||||||
|
}
|
||||||
|
catch (std::out_of_range&){
|
||||||
|
LOG(ERROR) << "Out of range: '" << kv[1] << "'";
|
||||||
|
throw OutOfRangeException();
|
||||||
|
}
|
||||||
|
catch (...){
|
||||||
|
LOG(ERROR) << "Invalid argument: '" << kv[1] << "'";
|
||||||
|
throw InvalidArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchiveConf::ParseType(const std::string& type) {
|
void ArchiveConf::ParseType(const std::string& type) {
|
||||||
if (type != "delete" && type != "swap") {
|
if (type != "delete" && type != "swap") {
|
||||||
LOG(ERROR) << "Invalid Archive";
|
LOG(ERROR) << "Invalid argument: type='" << type << "'";
|
||||||
assert(false);
|
throw InvalidArgumentException();
|
||||||
}
|
}
|
||||||
type_ = type;
|
type_ = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DBMetaOptions::DBMetaOptions(const std::string& dbpath, */
|
|
||||||
/* const std::string& uri) */
|
|
||||||
/* : path(dbpath), backend_uri(uri) { */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
} // namespace engine
|
} // namespace engine
|
||||||
} // namespace vecwise
|
} // namespace vecwise
|
||||||
} // namespace zilliz
|
} // namespace zilliz
|
||||||
|
|
Loading…
Reference in New Issue