ConstructorNotFoundException class final
Exception thrown when a requested constructor cannot be found or invoked for a given type during resolution.
Typically occurs when:
- A constructor name does not exist on a class
- The constructor exists but is inaccessible
- The resolver attempts to dynamically instantiate a type using metadata, reflection, or dependency injection mechanisms
This exception is part of the resolver error hierarchy and extends RuntimeResolverException, preserving its message, cause, and stack trace handling.
Usage Example
// Attempting to resolve a non-existent constructor
throw ConstructorNotFoundException(
"UserService",
"fromConfig",
cause: NoSuchMethodError,
);
Design Notes
- Provides clear, human-readable diagnostics referencing both the type and constructor name.
- Maintains exception chaining through the optional cause parameter.
- Used by dynamic resolution processes, such as reflection-based factories or dependency injection pipelines.
- Does not attempt to recover; this is a terminal resolution error.
Example Behavior
| Type | Constructor | Result |
|---|---|---|
UserRepository |
create |
❌ Throws ConstructorNotFoundException |
Config |
Config.load |
❌ Throws if method is not a constructor |
Widget |
unnamed constructor | ❌ Throws if unnamed constructor missing |
See Also
- Inheritance
-
- Object
- Error
- RuntimeException
- RuntimeResolverException
- ConstructorNotFoundException
- Available extensions
Constructors
- ConstructorNotFoundException(Object type, String ctorName, {Object? cause, StackTrace? stack})
- Exception thrown when a requested constructor cannot be found or invoked for a given type during resolution.
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