public class OverLimitException extends Exception
For example, ByteSource.allBytes(maxBytes)
reads all bytes
from the source into a ByteBuffer
, up to a limit.
If we invoke source.allBytes(1024)
, and the total number of bytes in the source exceeds 1024,
the action fails with a new OverLimitException("maxBytes", 1024)
.
Each OverLimitException
contains the name of the limit (for example "maxBytes"
)
and the value of the limit (for example 1024
).
The UI layer can use them to generate a more user-friendly error message, for example:
"The maximum number of bytes must not exceed 1024."
Note that OverLimitException
does not contain the information of
how much is exceeded beyond the limit.
Usually the action is aborted as soon as the limit is exceeded,
therefore it is unknown what the total amount would have been.
Constructor and Description |
---|
OverLimitException(String limitName,
long limitValue)
Example:
new OverLimitException("maxBytes", 1024) |
OverLimitException(String limitName,
long limitValue,
String message)
Example:
new OverLimitException("maxBytes", 1024, "number of bytes exceeds 1024") |
Instance Methods | |
---|---|
String |
getLimitName()
The name of the limit, for example,
"maxBytes" . |
long |
getLimitValue()
The value of the limit, for example,
1024 . |
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public OverLimitException(String limitName, long limitValue)
new OverLimitException("maxBytes", 1024)
public String getLimitName()
"maxBytes"
.public long getLimitValue()
1024
.