From 1bed2d20a5ccfae4ae7bdfadaaf03fcbe1dba449 Mon Sep 17 00:00:00 2001 From: Stephan Ewen Date: Fri, 17 Feb 2017 16:24:35 +0100 Subject: [PATCH] [FLINK-XXXX] [core] Add base Flink Exception classes --- .../util/DynamicCodeLoadingException.java | 52 +++++++++++++++ .../org/apache/flink/util/FlinkException.java | 65 +++++++++++++++++++ .../flink/util/FlinkRuntimeException.java | 65 +++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 flink-core/src/main/java/org/apache/flink/util/DynamicCodeLoadingException.java create mode 100644 flink-core/src/main/java/org/apache/flink/util/FlinkException.java create mode 100644 flink-core/src/main/java/org/apache/flink/util/FlinkRuntimeException.java diff --git a/flink-core/src/main/java/org/apache/flink/util/DynamicCodeLoadingException.java b/flink-core/src/main/java/org/apache/flink/util/DynamicCodeLoadingException.java new file mode 100644 index 0000000000000..f2c5f898b705c --- /dev/null +++ b/flink-core/src/main/java/org/apache/flink/util/DynamicCodeLoadingException.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package org.apache.flink.util; + +import org.apache.flink.annotation.Public; + +/** + * An exception that is thrown if the dynamic instantiation of code fails. + * + *

This exception is supposed to "sum up" the zoo of exceptions typically thrown around + * dynamic code loading and instantiations: + * + *

{@code
+ * try {
+ *     Class.forName(classname).asSubclass(TheType.class).newInstance();
+ * }
+ * catch (ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException e) {
+ *     throw new DynamicCodeLoadingException(e);
+ * }
+ * }
+ */ +@Public +public class DynamicCodeLoadingException extends FlinkException { + + private static final long serialVersionUID = -25138443817255490L; + + /** + * Creates a new exception with the given message and cause + * + * @param message The exception message + * @param cause The exception that caused this exception + */ + public DynamicCodeLoadingException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/flink-core/src/main/java/org/apache/flink/util/FlinkException.java b/flink-core/src/main/java/org/apache/flink/util/FlinkException.java new file mode 100644 index 0000000000000..f609770bc0a29 --- /dev/null +++ b/flink-core/src/main/java/org/apache/flink/util/FlinkException.java @@ -0,0 +1,65 @@ +/* + * 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. + */ + +package org.apache.flink.util; + +import org.apache.flink.annotation.Public; + +/** + * Base class of all Flink-specific checked exceptions. + */ +@Public +public class FlinkException extends Exception { + + private static final long serialVersionUID = 450688772469004724L; + + /** + * Creates a new exception with a null message and null cause. + */ + public FlinkException() { + super(); + } + + /** + * Creates a new Exception with the given message and null as the cause. + * + * @param message The exception message + */ + public FlinkException(String message) { + super(message); + } + + /** + * Creates a new exception with a null message and the given cause. + * + * @param cause The exception that caused this exception + */ + public FlinkException(Throwable cause) { + super(cause); + } + + /** + * Creates a new exception with the given message and cause + * + * @param message The exception message + * @param cause The exception that caused this exception + */ + public FlinkException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/flink-core/src/main/java/org/apache/flink/util/FlinkRuntimeException.java b/flink-core/src/main/java/org/apache/flink/util/FlinkRuntimeException.java new file mode 100644 index 0000000000000..24a33e2787515 --- /dev/null +++ b/flink-core/src/main/java/org/apache/flink/util/FlinkRuntimeException.java @@ -0,0 +1,65 @@ +/* + * 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. + */ + +package org.apache.flink.util; + +import org.apache.flink.annotation.Public; + +/** + * Base class of all Flink-specific unchecked exceptions. + */ +@Public +public class FlinkRuntimeException extends RuntimeException { + + private static final long serialVersionUID = 193141189399279147L; + + /** + * Creates a new exception with a null message and null cause. + */ + public FlinkRuntimeException() { + super(); + } + + /** + * Creates a new Exception with the given message and null as the cause. + * + * @param message The exception message + */ + public FlinkRuntimeException(String message) { + super(message); + } + + /** + * Creates a new exception with a null message and the given cause. + * + * @param cause The exception that caused this exception + */ + public FlinkRuntimeException(Throwable cause) { + super(cause); + } + + /** + * Creates a new exception with the given message and cause + * + * @param message The exception message + * @param cause The exception that caused this exception + */ + public FlinkRuntimeException(String message, Throwable cause) { + super(message, cause); + } +}