There are many languages that has coroutine.
Coroutine comes in two forms:
Python has stackless, semi coroutine.
In python, coroutine does not come as a form of class.
It is single interface, and you can't make calls from it.
def Fibonacci(n):
fn = 0; fn1 = fn
yield fn
fn = 1; fn2 = fn1; fn1 = fn
yield fn
#whild True:
for i in range(n-2):
fn = fn1 + fn2; fn2 = fn1; fn1 = n
yield fn
C++ didn't start with hierarchical exception, but laguages like JAVA started with one.
This helps step by step exception handling.
You want to catch exception by reference because if exception is caught by value, there may be truncation happening.
program keeps all exceptions, and the program can statically or dynamically tell if the exception is handled or not
Why is c++ not implementing static unhandled exception catch?
It prevents code reuse
it gets impossible to expect for exception if concurrency is involved
struct E{};
int cnt = 3;
void f(int i){
if (i == 0) throw E();
try {
f(i-1);
}catch (E) {
cnt -= 1;
if (cnt>0) f(2);
}
}
int main(){f(2);}
A stack can hold arbitrary number of exceptions in a stack.
However, multiple exceptions cannot propagate simultaneously
Destructor is called during propagation, so if you were to throw an exception in destructor, you need to call it in a block that is only called if it's not propagating.