-
Notifications
You must be signed in to change notification settings - Fork 0
Exception Handling
KlumAST supports a hierarchy of Exception to signal problems in the various phases of the model lifecycle. The hierarchy is as follows:
The KlumException is the base class for all exceptions thrown by KlumAST. It contains a reference to the phase in which the exception occurred.
The KlumModelException is thrown when a problem occurs during the creation of the model. It contains a reference to position in the model setup where the exception was thrown. This is provided using a breadcrumb string that mimics methods and closures used in the DSL.
This is NOT the path of the object in the actual model tree, but the path in the DSL script that was used to create the model. This is useful to identify the location of the problem in the script. This also includes objects generated by Templates or nested scripts.
Examples:
A model created from a script (Using Foo.Create.From(File)) will result in the prefix: $/Foo.From:file(<filename>). If given filename contains a script with the following content, the various breadcrumbs will be created:
name "bla"
// $/Foo.From:file(myFile)
bars {
// $/Foo.From:file(myFile)/bars
bar {
// $/Foo.From:file(myFile)/bars/bar
name "bar1"
}
bar {
// $/Foo.From:file(myFile)/bars/bar[2]
name "bar2"
}
}NOTE: Besides being part of the exception, the breadcrumb-path is also stored in the KlumInstanceProxy of the generated object.
The KlumVisitorException is thrown when a problem occurs during the traversal of the model tree, usually as partof the execution of a phase. It contains a reference to the object in the model tree that caused the exception.
The most notable use is the occurrence of Validation exceptions. Each failed validation check results in a single thrown KlumVisitorException that contains the object that failed the validation as well as a failure message. These single exceptions will finally be aggregated into a single KlumValidationException that contains all failed validations.
As stated above, a KlumValidationException is thrown when a validation fails. It contains a list of all failed validations, each represented by a KlumVisitorException, sorted by their occuring object.