bug 60128: close opened resources to avoid leaks; add exception as cause where available for more context for raised exceptions.