Class NaftahBugError
- All Implemented Interfaces:
Serializable
It extends AssertionError, indicating a serious, unexpected condition
that the program should never reach under normal circumstances.
Optionally carries a cause Throwable and a custom bug message.
The error message is prefixed with Arabic messages like
"خطأ برمجي!" to indicate developer or logic-level bugs.
- Author:
- Chakib Daii
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1.private final ThrowableThe underlying exception that caused this error, if any.private intThe line number on which the 1st character of this token was matched, line=1..n.private StringThe descriptive message text for the bug error.private static final longSerialization ID. -
Constructor Summary
ConstructorsConstructorDescriptionNaftahBugError(String message) Constructs aNaftahBugErrorusing the given message text.NaftahBugError(String msg, int line, int column) Constructs aNaftahBugErrorusing a descriptive message and the line number along with the column.NaftahBugError(String msg, Throwable exception) Constructs aNaftahBugErrorusing both a descriptive message and an underlying exception cause.NaftahBugError(String msg, Throwable exception, int line, int column) Constructs aNaftahBugErrorusing a descriptive message and an underlying exception cause and the line number along with the column.NaftahBugError(Throwable exception) Constructs aNaftahBugErrorusing the given cause. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringConstructs the internal message based on the presence of a user-defined message and an optional exception.Returns the raw bug message text without formatting or localization.getCause()Returns the underlying cause of this bug error, if available.Returns the detailed error message.booleanChecks whether the bug error has an associated line and column position.voidsetBugText(String msg) Updates the descriptive bug message.voidsetColumn(int column) Sets the column number where the bug was detected.voidsetLine(int line) Sets the line number where the bug was detected.toString()Returns the string representation of this error, which delegates togetMessage().Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization ID.- See Also:
-
exception
The underlying exception that caused this error, if any. -
line
private int lineThe line number on which the 1st character of this token was matched, line=1..n. -
column
private int columnThe index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1. -
message
The descriptive message text for the bug error.
-
-
Constructor Details
-
NaftahBugError
Constructs aNaftahBugErrorusing the given message text.- Parameters:
message- the error message describing the bug
-
NaftahBugError
Constructs aNaftahBugErrorusing a descriptive message and the line number along with the column.- Parameters:
msg- the error message describing the bugline- The line number on which the 1st character of this token was matchedcolumn- The index of the first character of this token relative to the beginning of the line at which it occurs
-
NaftahBugError
Constructs aNaftahBugErrorusing the given cause.- Parameters:
exception- the underlying cause of this error
-
NaftahBugError
Constructs aNaftahBugErrorusing both a descriptive message and an underlying exception cause.- Parameters:
msg- the error message describing the bugexception- the underlying cause of this error
-
NaftahBugError
Constructs aNaftahBugErrorusing a descriptive message and an underlying exception cause and the line number along with the column.- Parameters:
msg- the error message describing the bugexception- the underlying cause of this errorline- The line number on which the 1st character of this token was matchedcolumn- The index of the first character of this token relative to the beginning of the line at which it occurs
-
-
Method Details
-
toString
Returns the string representation of this error, which delegates togetMessage(). -
getMessage
Returns the detailed error message. If a message was provided during construction, it will be returned prefixed with"خطأ برمجي!". Otherwise, it will return the message from the exception cause, prefixed with"خطأ برمجي! استثناء غير ملتقط: "and localized usingExceptionLocalizer.localizeException(Throwable).- Overrides:
getMessagein classThrowable- Returns:
- the formatted bug message
-
doGetMessage
Constructs the internal message based on the presence of a user-defined message and an optional exception.- Returns:
- the constructed error detail string
-
getCause
Returns the underlying cause of this bug error, if available. -
getBugText
Returns the raw bug message text without formatting or localization.- Returns:
- the original bug message if set, otherwise the cause's message
-
setBugText
Updates the descriptive bug message.- Parameters:
msg- the new bug message
-
hasCodePosition
public boolean hasCodePosition()Checks whether the bug error has an associated line and column position.This method returns
trueif both the line and column numbers are set to valid values (i.e., not equal to-1), indicating the presence of a code position in the error. Otherwise, it returnsfalse.- Returns:
trueif the error has a valid line and column;falseotherwise.
-
setLine
public void setLine(int line) Sets the line number where the bug was detected.This method allows the line number to be specified for the bug error. The line number should be greater than
0, and it must be different from the column number for a valid update. If the provided line is-1, no update will occur.- Parameters:
line- The line number where the bug occurred (1-based index).- Throws:
IllegalArgumentException- If the line number is-1.
-
setColumn
public void setColumn(int column) Sets the column number where the bug was detected.This method allows the column number to be specified for the bug error. The column number should be greater than or equal to
0, and it must be different from the line number for a valid update. If the provided column is-1, no update will occur.- Parameters:
column- The column index (0-based) where the bug occurred.- Throws:
IllegalArgumentException- If the column number is-1.
-