slicing java programs that throw and catch exceptions

62
Slicing Java Programs that Throw and Catch Exceptions Matthew Allen Susan Horwitz University of Wisconsin-Madison PEPM 2003 San Diego, CA June 7, 2003

Upload: nenet

Post on 13-Jan-2016

27 views

Category:

Documents


3 download

DESCRIPTION

Slicing Java Programs that Throw and Catch Exceptions. Matthew Allen Susan Horwitz University of Wisconsin-Madison PEPM 2003 San Diego, CA June 7, 2003. Motivation. Exceptions: Important error-handling technique BUT: Current program-slicing algorithms don’t handle exceptions Goal: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs thatThrow and Catch Exceptions

Matthew Allen

Susan Horwitz

University of Wisconsin-Madison

PEPM 2003

San Diego, CA

June 7, 2003

Page 2: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 2

MotivationExceptions:

Important error-handling technique

BUT: Current program-slicing algorithms don’t handle

exceptions

Goal: Extend System Dependence Graph (SDG) based

slicing to support exceptions

Page 3: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 3

OutlineMotivation

Program Slicing

Slicing with the SDG

Extending SDG-Based Slicing to Handle Exceptions

Related Work

Conclusions

Page 4: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 4

Program Slicing

A slice from a component S is the set of

components that might affect:

Whether or how often S executes

The value of a variable used at S

Page 5: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 5

Slicing Exampleint x, y;

void foo() { fact(); print(x); print(y);}

void fact() { x = 1; while (y > 0) { x = x * y; y--; }}

Page 6: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 6

Slicing Exampleint x, y;

void foo() { fact(); print(x); print(y); slice from here}

void fact() { x = 1; while (y > 0) { x = x * y; y--; }}

Page 7: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 7

Slicing Exampleint x, y;

void foo() { fact(); print(x); print(y); slice from here}

void fact() { x = 1; while (y > 0) { x = x * y; y--; }}

Page 8: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 8

Slicing Programs with Exceptions

Exceptions can affect:

Whether or how often a statement executes

Value of a variable used at a statement

Page 9: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 9

Example: when/how often stmt executes

void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”);

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 10: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 10

void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”); Slice from here

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Example: when/how often stmt executes

Page 11: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 11

void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”); Slice from here

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Example: when/how often stmt executes

Page 12: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 12

Exception affects value of variable

void foo() {

try {

fact();

print(x);

}

catch (NegEx e) {

print(x);

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 13: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 13

Exception affects value of variable

void foo() {

try {

fact();

print(x);

}

catch (NegEx e) {

print(x); Slice from here

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 14: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 14

Exception affects value of variable

void foo() {

try {

fact();

print(x);

}

catch (NegEx e) {

print(x); Slice from here

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 15: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 15

Exception affects value of variable

void foo() {

try {

fact();

print(x);

}

catch (NegEx e) {

print(x); Slice from here

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 16: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 16

Exception affects value of variable

void foo() {

try {

fact();

print(x); Slice from here

}

catch (NegEx e) {

print(x);

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 17: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 17

Exception affects value of variable

void foo() {

try {

fact();

print(x); Slice from here

}

catch (NegEx e) {

print(x);

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Page 18: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 18

OutlineMotivation

Program Slicing

Slicing with the SDG (no exceptions)

Extending SDG-Based Slicing to Handle Exceptions

Related Work

Conclusions

Page 19: Slicing Java Programs that Throw and Catch Exceptions

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x)

print(y)

enter fact

x = 1

x = x * y

y--

call fact

exit

T

T

F

F

T

while (y > 0)

exit foo

F

Page 20: Slicing Java Programs that Throw and Catch Exceptions

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter fooy = y_in

print(x)

print(y)

enter facty = y_in

x = 1

x = x * y

y--

y_in = ycall factx = x_outy = y_out

x_out = xy_out = y

exit

T

T

F

F

T

while (y > 0)

exit foo

F

Page 21: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 21

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x) print(y)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

T T TT

T T T

TT T T T

T T

Page 22: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 22

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x) print(y)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

Page 23: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 23

print(y)

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

Page 24: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 24

print(y)

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

enter foo

call fact

y_in = y y = y_out

y = y_in

Page 25: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 25

print(y)

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact()

throws NegEx

{

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

enter foo

call fact

y_in = y y = y_out

y = y_in

enter fact

while (y > 0)

y--

y=y_in y_out=y

Page 26: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 26

OutlineMotivation

Program Slicing

Slicing with the SDG

Extending SDG-Based Slicing to Handle Exceptions

Related Work

Conclusions

Page 27: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 27

Example Revisited

static void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”); Slice from here

}

}

static void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

Page 28: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 28

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(“no error”)

print(“error”)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

Page 29: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 29

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(“no error”)

print(“error”)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

catch(NegEx e)

NegExexit

throw newNegEx()

if(y<0)

Page 30: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 30

static void fact()

throws NegEx

{

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

Page 31: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 31

static void fact()

throws NegEx

{

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

enter facty = y_in

x=1

if(y<0)

throw new NegEx()

while (y>0)

x_out = xy_out = y

exit

x=x*y

y--

T

T

T

F

F

F

Page 32: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 32

static void fact() {

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

enter facty = y_in

x=1

if(y<0)

throw new NegEx()

while (y>0)

x_out = xy_out = y

exit

x=x*y

y--

T

T

T

F

F

NegEx exit

F

Page 33: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 33

static void fact() {

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

enter facty = y_in

x=1

if(y<0)

throw new NegEx()

while (y>0)

x_out = xy_out = y

exit

x=x*y

y--

T

T

T

F

F

NegEx exit

normal exit

F

Page 34: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 34

static void fact() {

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

enter facty = y_in

x=1

if(y<0)

throw new NegEx()

while (y>0)

x_out = xy_out = y

exit

x=x*y

y--

T

T

T

F

F

NegEx exit

F

normal exit

TF

Page 35: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 35

static void fact() {

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

enter facty = y_in

x=1

if(y<0)

throw new NegEx()

while (y>0)

x_out = xy_out = y

exit

x=x*y

y--

T

T

T

F

F

NegEx exit

F

normal exit

TF

Page 36: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 36

static void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”);

}

}

enter foo

try

y = y_incall fact

catch(NegEx e)

print(“no error”)

print(“error”)

x_out = xy_out = y

exit

Page 37: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 37

static void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”);

}

}

enter foo

try

y = y_incall fact

normalreturn

catch(NegEx e)

print(“no error”)

print(“error”)

x_out = xy_out = y

exit

normal NegEx

Page 38: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 38

static void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”);

}

}

enter foo

try

y = y_incall fact

normalreturn

catch(NegEx e)

print(“no error”)

print(“error”)

x_out = xy_out = y

exit

normal NegEx

T TF F

Page 39: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 39

static void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”);

}

}

enter foo

try

y = y_incall fact

normalreturn

catch(NegEx e)

print(“no error”)

print(“error”)

x_out = xy_out = y

exit

normal NegEx

T TF F

TF

Page 40: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 40

static void foo() {

try {

fact();

print(“no error”);

}

catch (NegEx e) {

print(“error”);

}

}

enter foo

try

y = y_incall fact

normalreturn

catch(NegEx e)

print(“no error”)

print(“error”)

x_out = xy_out = y

exit

normal NegEx

T TF F

TF

Page 41: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 41

Example revisited

static void foo() {

try {

fact();

print(x);

}

catch (NegEx e) {

print(x); Slice from here

}

}

static void fact() {

x = 1;

if (y < 0)

throw new NegEx ();

while (y > 0) {

x = x * y;

y--;

}

}

Page 42: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 42

print(x)

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

x=x_out

x_out=xx=1

x=x*y

Page 43: Slicing Java Programs that Throw and Catch Exceptions

enter foo

y=y_in try

call fact

y_in=ynormalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0)

throw newNegEx()

while(y>0)

normalexit

NegExexit x=x*y y--

x_out=xy_out=y

x_out=xy_out=y

x=x_out y=y_out print(x)x=x_out y=y_out

Page 44: Slicing Java Programs that Throw and Catch Exceptions

enter foo

y=y_in try

call fact

y_in=ynormalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0)

throw newNegEx()

while(y>0)

normalexit

NegExexit x=x*y y--

x_out=xy_out=y

x_out=xy_out=y

x=x_out y=y_out print(x)x=x_out y=y_outx=x_out

x_out=x

x=1

Page 45: Slicing Java Programs that Throw and Catch Exceptions

enter foo

y=y_in try

call fact

y_in=ynormalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0)

throw newNegEx()

while(y>0)

normalexit

NegExexit x=x*y y--

x_out=xy_out=y

x_out=xy_out=y

x=x_out y=y_out print(x)x=x_out y=y_out

Page 46: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 46

Other Issues finally clauses Unchecked exceptions

See paper!

Page 47: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 47

OutlineMotivation

Program Slicing

Slicing with the SDG

Extending SDG-Based Slicing to Handle Exceptions

Related Work

Conclusions

Page 48: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 48

Related Work[Sinha / Harrold / Rothermel 1999]

Addresses slicing programs with exceptions. Some similar aspects . Problems:

Does not correctly represent interprocedural control dependences when length of call chain from try to throw is greater than 1.

Does not address data dependences.

[Sinha / Harrold 1998, 2000]

Addresses handling finally clauses. See paper.

Page 49: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 49

ConclusionsSlicing is an important operation.

Slicing Java programs is an area of current interest.

Contribution:

Extend SDG-based Slicing: To correctly handle exceptions.

Changes only to CFG. Same slicing algorithm!

Page 50: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 50

void foo() {

try {

fact();

print(“no error”); Slice from here

}

catch (NegEx e) {

print(“error”);

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Example: when/how often stmt executes

Page 51: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 51

void foo() {

try {

fact();

print(“no error”); Slice from here

}

catch (NegEx e) {

print(“error”);

}

}

void fact() throws NegEx {

x = 1;

if (y < 0)

throw new NegEx();

while (y > 0) {

x = x * y;

y--;

}

}

Example: when/how often stmt executes

Page 52: Slicing Java Programs that Throw and Catch Exceptions

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact() {

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter fooy = y_in

print(x)

print(y)

enter facty = y_in

x = 1

x = x * y

y--

y_in = ycall factx = x_outy = y_out

x_out = xy_out = y

exit

T

T

F

F

T

while (y > 0)

exit foo

F

datadependence

controldependence

TTT

T

TT

T

Page 53: Slicing Java Programs that Throw and Catch Exceptions

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact() {

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter fooy = y_in

print(x)

print(y)

enter facty = y_in

x = 1

x = x * y

y--

y_in = ycall factx = x_outy = y_out

x_out = xy_out = y

exit

while (y > 0)

exit foo datadependence

controldependence

TTT

T

TT

T

Page 54: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 54

print(y)

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact() {

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

Page 55: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 55

print(y)

CFGPDGSDG

static void foo() {

fact();

print(x);

print(y);

}

static void fact() {

x = 1;

while (y > 0) {

x = x * y;

y--;

}

}

enter foo

print(x)

enter fact

x = 1 while (y > 0)

x = x * y y--

call fact

y_in = y x = x_out y = y_out

y=y_in

y = y_in

x_out=x y_out=y

Page 56: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 56

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(“no error”)

print(“error”)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

Page 57: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 57

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(“no error”)

print(“error”)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

Page 58: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 58

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(“no error”)

print(“error”)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

Page 59: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 59

print(x)

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

Page 60: Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions – Allen / HorwitzSlide 60

print(x)

enter foo

y=y_in try

call fact

y_in=y x=x_out y=y_out normalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0) x_out=x y_out=y

throw newNegEx()

while(y>0)

normalexit

NegExexit

x=x*y y--

Page 61: Slicing Java Programs that Throw and Catch Exceptions

enter foo

y=y_in try

call fact

y_in=ynormalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0)

throw newNegEx()

while(y>0)

normalexit

NegExexit x=x*y y--

x_out=xy_out=y

x_out=xy_out=y

x=x_out y=y_out print(x)x=x_out y=y_out

Page 62: Slicing Java Programs that Throw and Catch Exceptions

enter foo

y=y_in try

call fact

y_in=ynormalreturn

catch(NegEx e)

enter factprint(x)

y=y_in x=1 if(y<0)

throw newNegEx()

while(y>0)

normalexit

NegExexit x=x*y y--

x_out=xy_out=y

x_out=xy_out=y

x=x_out y=y_out print(x)x=x_out y=y_out