Class SourceException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.opendaylight.yangtools.yang.parser.spi.source.SourceException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
InferenceException
,InvalidSubstatementException
,MissingSubstatementException
,YangVersionLinkageException
Thrown to indicate error in YANG model source.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSourceException
(@NonNull String message, @NonNull CommonStmtCtx stmt) Create a new instance with the specified message and source.SourceException
(@NonNull String message, @NonNull CommonStmtCtx stmt, Throwable cause) Create a new instance with the specified message and source.SourceException
(@NonNull String message, @NonNull StatementSourceReference source) Create a new instance with the specified message and source.SourceException
(@NonNull String message, @NonNull StatementSourceReference source, Throwable cause) Create a new instance with the specified message and source.SourceException
(@NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message.SourceException
(@NonNull CommonStmtCtx stmt, Throwable cause, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message.SourceException
(@NonNull StatementSourceReference source, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message.SourceException
(@NonNull StatementSourceReference source, Throwable cause, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message. -
Method Summary
Modifier and TypeMethodDescription@NonNull StatementSourceReference
Return the reference to the source which caused this exception.static void
throwIf
(boolean expression, @NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Throw an instance of this exception if an expression evaluates to true.static void
throwIf
(boolean expression, @NonNull StatementSourceReference source, @NonNull String format, Object... args) Throw an instance of this exception if an expression evaluates to true.static <T> @NonNull T
throwIfNull
(@Nullable T obj, @NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Throw an instance of this exception if an object is null.static <T> @NonNull T
throwIfNull
(@Nullable T obj, @NonNull StatementSourceReference source, @NonNull String format, Object... args) Throw an instance of this exception if an object is null.static <T> @NonNull T
unwrap
(Optional<T> opt, @NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Throw an instance of this exception if an optional is not present.static <T> @NonNull T
unwrap
(Optional<T> opt, @NonNull StatementSourceReference source, @NonNull String format, Object... args) Throw an instance of this exception if an optional is not present.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
SourceException
Create a new instance with the specified message and source. The message will be appended with the source reference.- Parameters:
message
- Context messagesource
- Statement source
-
SourceException
public SourceException(@NonNull String message, @NonNull StatementSourceReference source, Throwable cause) Create a new instance with the specified message and source. The message will be appended with the source reference.- Parameters:
message
- Context messagesource
- Statement sourcecause
- Underlying cause of this exception
-
SourceException
public SourceException(@NonNull StatementSourceReference source, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message. The message will be appended with the source reference.- Parameters:
source
- Statement sourceformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
-
SourceException
public SourceException(@NonNull StatementSourceReference source, Throwable cause, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message. The message will be appended with the source reference.- Parameters:
source
- Statement sourcecause
- Underlying cause of this exceptionformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
-
SourceException
Create a new instance with the specified message and source. The message will be appended with the source reference.- Parameters:
message
- Context messagestmt
- Statement context, not retained
-
SourceException
Create a new instance with the specified message and source. The message will be appended with the source reference.- Parameters:
message
- Context messagestmt
- Statement context, not retainedcause
- Underlying cause of this exception
-
SourceException
Create a new instance with the specified source and a formatted message. The message will be appended with the source reference.- Parameters:
stmt
- Statement context, not retainedformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
-
SourceException
public SourceException(@NonNull CommonStmtCtx stmt, Throwable cause, @NonNull String format, Object... args) Create a new instance with the specified source and a formatted message. The message will be appended with the source reference.- Parameters:
stmt
- Statement context, not retainedcause
- Underlying cause of this exceptionformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
-
-
Method Details
-
getSourceReference
Return the reference to the source which caused this exception.- Returns:
- Source reference
-
throwIf
public static void throwIf(boolean expression, @NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Throw an instance of this exception if an expression evaluates to true. If the expression evaluates to false, this method does nothing.- Parameters:
expression
- Expression to be evaluatedstmt
- Statement context, not retainedformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
- Throws:
SourceException
- if the expression evaluates to true.
-
throwIf
public static void throwIf(boolean expression, @NonNull StatementSourceReference source, @NonNull String format, Object... args) Throw an instance of this exception if an expression evaluates to true. If the expression evaluates to false, this method does nothing.- Parameters:
expression
- Expression to be evaluatedsource
- Statement source referenceformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
- Throws:
SourceException
- if the expression evaluates to true.
-
throwIfNull
public static <T> @NonNull T throwIfNull(@Nullable T obj, @NonNull StatementSourceReference source, @NonNull String format, Object... args) Throw an instance of this exception if an object is null. If the object is non-null, it will be returned as the result of this method.- Parameters:
obj
- Object reference to be checkedsource
- Statement source referenceformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
- Returns:
- Object if it is not null
- Throws:
SourceException
- if object is null
-
throwIfNull
public static <T> @NonNull T throwIfNull(@Nullable T obj, @NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Throw an instance of this exception if an object is null. If the object is non-null, it will be returned as the result of this method.- Parameters:
obj
- Object reference to be checkedstmt
- Statement context, not retainedformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
- Returns:
- Object if it is not null
- Throws:
SourceException
- if object is null
-
unwrap
public static <T> @NonNull T unwrap(Optional<T> opt, @NonNull StatementSourceReference source, @NonNull String format, Object... args) Throw an instance of this exception if an optional is not present. If it is present, this method will return the unwrapped value.- Parameters:
opt
- Optional to be checkedsource
- Statement source referenceformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
- Returns:
- Object unwrapped from the opt optional
- Throws:
SourceException
- if the optional is not present
-
unwrap
public static <T> @NonNull T unwrap(Optional<T> opt, @NonNull CommonStmtCtx stmt, @NonNull String format, Object... args) Throw an instance of this exception if an optional is not present. If it is present, this method will return the unwrapped value.- Parameters:
opt
- Optional to be checkedstmt
- Statement context, not retainedformat
- Format string, according toString.format(String, Object...)
.args
- Format string arguments, according toString.format(String, Object...)
- Returns:
- Object unwrapped from the opt optional
- Throws:
SourceException
- if the optional is not present
-