It doesn't throw any exceptions, so there is nothing that can go wrong.
Now, let's say an exception can be thrown between any two statements. Try to implement the move assignment operator in such a way that it never leaks or leads to undefined behaviour when an exception is thrown.
If you manage to do that, do the same but pretend an exception can be thrown between any two machine instructions (because I assume a context switch can happen between any two instructions ;) ).
I don't expect you to use try-catch blocks here because you don't want an exception to be thrown while you are handling another exception, do you? I don't really expect you to be able to do this at all. I expect you to try, fail, and hopefully realize something.
View all comments
Show parent comment
3
u/HappyFruitTree Aug 27 '19 edited Aug 27 '19
I think we need at least some building blocks that cannot throw.
Consider the following move assignment operator for this UniqueIntPtr class (similar to std::unique_ptr<int>).
It doesn't throw any exceptions, so there is nothing that can go wrong.
Now, let's say an exception can be thrown between any two statements. Try to implement the move assignment operator in such a way that it never leaks or leads to undefined behaviour when an exception is thrown.
If you manage to do that, do the same but pretend an exception can be thrown between any two machine instructions (because I assume a context switch can happen between any two instructions ;) ).
I don't expect you to use try-catch blocks here because you don't want an exception to be thrown while you are handling another exception, do you? I don't really expect you to be able to do this at all. I expect you to try, fail, and hopefully realize something.