< The Science of Programming < SwayPresentations < Objects
Examples
How about try blocks? Using the Sway proximal block style:
var error;
try (error)
{
a / b;
}
else if (error . type == :undefinedVariable)
{
println("try block has an undefined variable");
}
else
{
println("try block has a divide error");
}
Here's the implementation:
function try($store,$code,$)
{
var result = catch(force($code));
if (error?(result))
{
$store = result;
if ($ != :null,force(car($)));
}
else
{
result;
}
}
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.