| 1 | // Licensed to the Apache Software Foundation (ASF) under one |
| 2 | // or more contributor license agreements. See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership. The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | #ifndef PARQUET_EXCEPTION_H |
| 19 | #define PARQUET_EXCEPTION_H |
| 20 | |
| 21 | #include <exception> |
| 22 | #include <sstream> |
| 23 | #include <string> |
| 24 | |
| 25 | #include "arrow/status.h" |
| 26 | #include "parquet/platform.h" |
| 27 | |
| 28 | // PARQUET-1085 |
| 29 | #if !defined(ARROW_UNUSED) |
| 30 | #define ARROW_UNUSED(x) UNUSED(x) |
| 31 | #endif |
| 32 | |
| 33 | #define PARQUET_CATCH_NOT_OK(s) \ |
| 34 | try { \ |
| 35 | (s); \ |
| 36 | } catch (const ::parquet::ParquetException& e) { \ |
| 37 | return ::arrow::Status::IOError(e.what()); \ |
| 38 | } |
| 39 | |
| 40 | #define PARQUET_IGNORE_NOT_OK(s) \ |
| 41 | do { \ |
| 42 | ::arrow::Status _s = (s); \ |
| 43 | ARROW_UNUSED(_s); \ |
| 44 | } while (0) |
| 45 | |
| 46 | #define PARQUET_THROW_NOT_OK(s) \ |
| 47 | do { \ |
| 48 | ::arrow::Status _s = (s); \ |
| 49 | if (!_s.ok()) { \ |
| 50 | std::stringstream ss; \ |
| 51 | ss << "Arrow error: " << _s.ToString(); \ |
| 52 | throw ::parquet::ParquetException(ss.str()); \ |
| 53 | } \ |
| 54 | } while (0) |
| 55 | |
| 56 | namespace parquet { |
| 57 | |
| 58 | class ParquetException : public std::exception { |
| 59 | public: |
| 60 | PARQUET_NORETURN static void EofException(const std::string& msg = "" ) { |
| 61 | std::stringstream ss; |
| 62 | ss << "Unexpected end of stream" ; |
| 63 | if (!msg.empty()) { |
| 64 | ss << ": " << msg; |
| 65 | } |
| 66 | throw ParquetException(ss.str()); |
| 67 | } |
| 68 | |
| 69 | PARQUET_NORETURN static void NYI(const std::string& msg = "" ) { |
| 70 | std::stringstream ss; |
| 71 | ss << "Not yet implemented: " << msg << "." ; |
| 72 | throw ParquetException(ss.str()); |
| 73 | } |
| 74 | |
| 75 | explicit ParquetException(const char* msg) : msg_(msg) {} |
| 76 | |
| 77 | explicit ParquetException(const std::string& msg) : msg_(msg) {} |
| 78 | |
| 79 | explicit ParquetException(const char* msg, std::exception&) : msg_(msg) {} |
| 80 | |
| 81 | ~ParquetException() throw() override {} |
| 82 | |
| 83 | const char* what() const throw() override { return msg_.c_str(); } |
| 84 | |
| 85 | private: |
| 86 | std::string msg_; |
| 87 | }; |
| 88 | |
| 89 | } // namespace parquet |
| 90 | |
| 91 | #endif // PARQUET_EXCEPTION_H |
| 92 | |