Name:
Anonymous
2010-08-24 8:59
#include <iostream>
using std::cout;
using std::endl;
class Integer
{
public:
Integer( int i ) : i_( i ) {}
operator int() { return i_; }
protected:
int i_;
};
class Fibonacci : public Integer
{
public:
Fibonacci( int i );
};
Fibonacci::Fibonacci( int i ) : Integer( i )
{
try {
if ( i == 0 || i == 1 ) {
throw Integer( i );
} else {
throw Integer( Fibonacci( i - 1 ) + Fibonacci( i - 2 ) );
}
} catch ( Integer ex ) {
i_ = ex;
}
}
int main()
{
const int UNTIL = 20;
for ( int loop = 0; loop < UNTIL; ++loop ) {
Fibonacci fibo( loop );
cout << fibo << ' ';
}
cout << endl;
return 0;
}
Name:
Anonymous
2011-11-02 23:14
Smalltime. Perl 6 raises an exception for everything! (Even
return.)
http://perlcabal.org/syn/S04.html#Control_Exceptions
Push that in your stack and pop it.