FieldAccessException class final
Exception thrown when reading a field or getter fails on a given type.
This error is typically raised when:
- The specified field does not exist
- Access to the field or getter is restricted (e.g., private or protected)
- The resolver attempts dynamic field access using reflection or metadata
Extends RuntimeResolverException, inheriting support for:
message— a description of the errorcause— optional underlying exceptionstackTrace— optional diagnostic stack trace
Usage Example
throw FieldAccessException(
"User",
"password",
cause: NoSuchMethodError(),
);
Design Notes
- Provides clear diagnostics including both type and field name.
- Supports exception chaining for better debugging.
- Indicates a terminal resolution error; cannot automatically recover.
Example Behavior
| Type | Field/Getter | Result |
|---|---|---|
User |
email |
❌ Throws if field missing or inaccessible |
Config |
version |
❌ Throws if getter not available |
Widget |
private property | ❌ Throws on restricted access |
See Also
- Inheritance
-
- Object
- Error
- RuntimeException
- RuntimeResolverException
- FieldAccessException
- Available extensions
Constructors
- FieldAccessException(Object type, String fieldName, {Object? cause, StackTrace? stack})
- Exception thrown when reading a field or getter fails on a given type.
Properties
- cause → Object?
-
The underlying cause of this exception, if any.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
The message describing the error.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace
-
The associated stack trace.
finalinherited
Methods
-
getCause(
) → Object -
The cause of this exception, if any.
inherited
-
getMessage(
) → String -
The message associated with this exception.
inherited
-
getStackTrace(
) → StackTrace -
The stack trace associated with this exception.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
printStackTrace(
[bool useErrorPrint = false]) → void -
Available on Error, provided by the ErrorExtensions extension
Prints the error along with its stack trace. -
printStackTrace(
[StackTrace? stacktrace, bool useErrorPrint = false]) → void -
Available on Exception, provided by the ExceptionExtensions extension
Prints the exception and optional StackTrace if available. -
printStackTrace(
[bool useErrorPrint = false]) → void -
Available on RuntimeException, provided by the RuntimeExceptionExtensions extension
Extension on RuntimeException to support pretty stack trace printing. -
printStackTrace(
[bool useErrorPrint = false]) → void -
Available on Throwable, provided by the ThrowableExtensions extension
Extension on Throwable to support printing stack traces in a unified way. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited