Added a test case for testing exception handling.
Changed to use shortcuts to access outer scopes.