2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.api.meta;
10 import static java.util.Objects.requireNonNull;
12 import java.io.IOException;
13 import java.io.NotSerializableException;
14 import java.io.ObjectInputStream;
15 import java.io.ObjectOutputStream;
16 import java.io.ObjectStreamException;
17 import org.eclipse.jdt.annotation.NonNull;
20 * An exception identifying a problem detected at a particular YANG statement. Exposes {@link #sourceRef()} to that
23 public class StatementSourceException extends RuntimeException {
25 private static final long serialVersionUID = 2L;
27 private final @NonNull StatementSourceReference sourceRef;
29 public StatementSourceException(final StatementSourceReference sourceRef, final String message) {
30 super(createMessage(sourceRef, message));
31 this.sourceRef = requireNonNull(sourceRef);
34 public StatementSourceException(final StatementSourceReference sourceRef, final String message,
35 final Throwable cause) {
36 super(createMessage(sourceRef, message), cause);
37 this.sourceRef = requireNonNull(sourceRef);
40 public StatementSourceException(final StatementSourceReference sourceRef, final String format,
41 final Object... args) {
42 this(sourceRef, format.formatted(args));
45 public StatementSourceException(final StatementSourceReference sourceRef, final Throwable cause,
46 final String format, final Object... args) {
47 this(sourceRef, format.formatted(args), cause);
50 private static String createMessage(final StatementSourceReference sourceRef, final String message) {
51 return requireNonNull(message) + " [at " + requireNonNull(sourceRef) + ']';
55 * Return the reference to the source which caused this exception.
57 * @return the reference to the source which caused this exception
59 public final @NonNull StatementSourceReference sourceRef() {
64 private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
69 private void readObjectNoData() throws ObjectStreamException {
74 private void writeObject(final ObjectOutputStream stream) throws IOException {
78 protected final void throwNSE() throws NotSerializableException {
79 throw new NotSerializableException(getClass().getName());