Errors
Exceptions
All the errors generated by Alchemic are related to incorrect usage. For example, trying to set a factory method to be an external reference to an instance, or trying to inject multiple objects into a single variable. Because these should be caught and dealt with by the developer, Alchemic throws them as instances of ALCException
, which extends NSException
.
This is in line with Apple’s recommendations which indicate that exceptions should be used for programming errors and NSError
references used for data errors.
Circular dependency detection
It’s possible with dependencies to get into a situation where the dependencies of one object reference a second object which needs the first to resolve. In other words, a chicken and egg situation.
Circular references through class variables are allowed by Alchemic as objects are instantiated before their dependencies are wired up. Circular dependencies involving arguments to methods are not allowed as the dependency has to be resolved before the method can be called.
Alchemic attempts to detect these endless loops of dependencies when it starts up by checking through the references that have been added to the model and looking for loops involving methods. If it detects one it will immediately throw a ALCCircularReferenceException
exception.