added exception handling on endWidget() call