tryTest.frink

Download or view tryTest.frink in plain text format


// This tests try/finally blocks.

// Case 1
try
{
   a = 2+2
}
finally
{
   beep[1]
}


// Case 2
try
{
   a = 2+2
}
finally
   beep[2]


// Case 3
try
   a = 2+2
finally
{
   beep[3]
}


// Case 4
try
   a = 2+2
finally
   beep[4]

// Case Scoping1
try
{
   zz = 1001
   println["zz is $zz"]
}
finally
   beep["Scoping1: zz is $zz"]

println["Return value of f[] is " + f[]]
println["Return value of g[] is " + g[]]


// Case 7
try
{
   // This can't be written as a literal "1/0" because that gets evaluated
   // at compile time.
   a = 0
   b = 1 / a
}
finally
   beep[7]



beep[x] :=  println["Finally block called for case $x"]

// Test from within a function in the face of return.
f[] :=
{
   try
      return 1
   finally
      beep[5]
}


// The "return" statement in the finally block will actually override the
// return in the try block.
g[] :=
{
   try
      return 1
   finally
   {
      beep[6]
      return 2
   }
}


Download or view tryTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19973 days, 2 hours, 55 minutes ago.