Outprintln caught systemoutprintln here in bar

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a try/catch block whose catch clause declares a supertype of the excepAon being thrown. If no matching catch is found, abort the program with an error. CIS120 / Spring 2012 Exception! Abstract Stack Machine Workspace Stack Program terminated with uncaught excepAon ( )! Discard the current workspace. Then, pop saved workspace frames off the stack, looking for the most recently pushed one that contains a try/catch block whose catch clause declares a supertype of the excepAon being thrown. If no matching catch is found, abort the program with an error. CIS120 / Spring 2012 Heap C! Exception! Catching the ExcepAon class C {! !public void foo() {! ! !this.bar();! ! !System.out.println(“here in foo”);! !}! !public void bar() {! ! !try { ! ! ! ! ! !this.baz();! ! !} catch (Exception e) { System.out.println(“caught”); }! ! !System.out.println(“here in bar”);! !}! !public void baz() {! ! !throw new Exception();! !}! }! •  Now what happens if we do (new C()).foo();? CIS120 / Spring 2012 Abstract Stack Machine Workspace (new C()).foo();! CIS120 / Spring 2012 Stack Heap Abstract Stack Machine Workspace (new C()).foo();! CIS120 / Spring 2012 Stack Heap Abstract Stack Machine Workspace Stack ().foo();! Allocate a new instance of C in the heap. CIS120 / Spring 2012 Heap C! Abstract Stack Machine Workspace ().foo();! CIS120 / Spring 2012 Stack Heap C! Abstract Stack Machine Workspace this.bar();! System.out.println(
 “here in foo”);! Stack _;! Heap C! this! Save a copy of the current workspace in the stack, leaving a “hole”, wriren _, where we return to. Push the this pointer, followed by arguments (in this case none) onto the stack. CIS120 / Spring 2012 Abstract Stack Machine Workspace this.bar();! System.out.println(
 “here in foo”);! CIS120 / Spring 2012 Stack _;! this! Heap C! Abstract Stack Machine Workspace try try {! this.baz baz();! ();! } catch (Exception e) { System.out.Println 
 (“caught”); } ! System.out.println(
 “here in bar”);! Stack _;! this! _;! System.out.println(
 “here in foo”);! this! CIS120 / Spring 2012 Heap C! Abstract St...
View Full Document

Ask a homework question - tutors are online