001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.nabla.algorithmic.forward.analysis;
018
019 import org.apache.commons.nabla.core.DifferentiationException;
020
021 /** Class used for delayed error reporting.
022 */
023 public class ErrorReporter {
024
025 /** Error report. */
026 private DifferentiationException reportedError;
027
028 /** Register an exception to be reported later.
029 * @param exception exception to be reported
030 */
031 public void register(final DifferentiationException exception) {
032 reportedError = exception;
033 }
034
035 /** Check if an error has already been registered.
036 * @return true if an error has already been registered
037 */
038 public boolean hasError() {
039 return reportedError != null;
040 }
041
042 /** Report the error if any.
043 * <p>If not error has been reported (i.e. if {@link #hasError()} returns
044 * <code>false</code>), this method does nothing. Otherwise, it rethrows
045 * the original exception.</p>
046 * @exception DifferentiationException if some error occurred
047 * during differentiation
048 */
049 public void reportErrors() throws DifferentiationException {
050 if (reportedError != null) {
051 throw reportedError;
052 }
053 }
054
055 }