Exception.h 1.7 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

X
Xu Peng 已提交
18 19
#pragma once

20 21
#include "utils/Error.h"

X
Xu Peng 已提交
22 23 24 25
#include <exception>
#include <string>

namespace zilliz {
J
jinhai 已提交
26
namespace milvus {
X
Xu Peng 已提交
27 28 29

class Exception : public std::exception {
public:
30
    Exception(ErrorCode code, const std::string& message)
G
groot 已提交
31
        : code_(code),
32
          message_(message) {
X
Xu Peng 已提交
33 34
        }

35 36 37
    ErrorCode code() const throw() {
        return code_;
    }
X
Xu Peng 已提交
38 39 40 41 42 43 44 45 46 47 48 49

    virtual const char* what() const throw() {
        if (message_.empty()) {
            return "Default Exception.";
        } else {
            return message_.c_str();
        }
    }

    virtual ~Exception() throw() {};

protected:
50
    ErrorCode code_;
X
Xu Peng 已提交
51 52 53 54 55
    std::string message_;
};

class InvalidArgumentException : public Exception {
public:
56 57 58 59 60 61 62 63
    InvalidArgumentException()
        : Exception(SERVER_INVALID_ARGUMENT, "Invalid Argument") {

    };
    InvalidArgumentException(const std::string& message)
        : Exception(SERVER_INVALID_ARGUMENT, message) {

    };
X
Xu Peng 已提交
64 65 66

};

J
jinhai 已提交
67
} // namespace milvus
X
Xu Peng 已提交
68
} // namespace zilliz