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
27#include "parquet/util/macros.h"
28
29// PARQUET-1085
30#if !defined(ARROW_UNUSED)
31#define ARROW_UNUSED(x) UNUSED(x)
32#endif
33
34#define PARQUET_CATCH_NOT_OK(s) \
35 try { \
36 (s); \
37 } catch (const ::parquet::ParquetException& e) { \
38 return ::arrow::Status::IOError(e.what()); \
39 }
40
41#define PARQUET_IGNORE_NOT_OK(s) \
42 do { \
43 ::arrow::Status _s = (s); \
44 ARROW_UNUSED(_s); \
45 } while (0)
46
47#define PARQUET_THROW_NOT_OK(s) \
48 do { \
49 ::arrow::Status _s = (s); \
50 if (!_s.ok()) { \
51 std::stringstream ss; \
52 ss << "Arrow error: " << _s.ToString(); \
53 throw ::parquet::ParquetException(ss.str()); \
54 } \
55 } while (0)
56
57namespace parquet {
58
59class ParquetException : public std::exception {
60 public:
61 PARQUET_NORETURN static void EofException(const std::string& msg = "") {
62 std::stringstream ss;
63 ss << "Unexpected end of stream";
64 if (!msg.empty()) {
65 ss << ": " << msg;
66 }
67 throw ParquetException(ss.str());
68 }
69
70 PARQUET_NORETURN static void NYI(const std::string& msg = "") {
71 std::stringstream ss;
72 ss << "Not yet implemented: " << msg << ".";
73 throw ParquetException(ss.str());
74 }
75
76 explicit ParquetException(const char* msg) : msg_(msg) {}
77
78 explicit ParquetException(const std::string& msg) : msg_(msg) {}
79
80 explicit ParquetException(const char* msg, std::exception& e) : msg_(msg) {}
81
82 ~ParquetException() throw() override {}
83
84 const char* what() const throw() override { return msg_.c_str(); }
85
86 private:
87 std::string msg_;
88};
89
90} // namespace parquet
91
92#endif // PARQUET_EXCEPTION_H
93