Suppose i have a demo method that returns a dynamic dataset and that may or may not return an exception.
Calling this method may look like this.
Now when the method does throw an exception the delete object statement in the finally block fails because the dataset-handle is null. The dynamic dataset itself still exists and needs to be cleaned up. What is the proper way to make sure the dynamic dataset gets cleaned up ?
Code:
block-level on error undo, throw.
class democlass:
method public void demomethod (output dataset-handle dshDEMO):
define variable doException as logical init yes.
create dataset dshDEMO.
dshDEMO:read-xmlschema("file", "demo.xsd", false).
dshDEMO:read-xml("file", "demo.xml", "EMPTY", ?, ?).
if doException
then undo, throw new Progress.Lang.AppError("Nope!", 101).
end method.
end class.
Calling this method may look like this.
Code:
block-level on error undo, throw.
define variable dc as class democlass no-undo.
define variable dsh as handle no-undo.
dc = new democlass().
dc:demomethod(output dataset-handle dsh by-reference).
MESSAGE "no Exception"
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
catch anError as Progress.Lang.Error:
MESSAGE anError:getMessage(1)
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK title "Exception".
end catch.
finally:
delete object dsh.
end finally.
Now when the method does throw an exception the delete object statement in the finally block fails because the dataset-handle is null. The dynamic dataset itself still exists and needs to be cleaned up. What is the proper way to make sure the dynamic dataset gets cleaned up ?