A Cake Eating Problem in Continuous Time: Hamiltonian or HJB?
The comment by user @MaartenPunt is accurate. I don't think that in general one can identify situations where one should have a clear preference over one formulation over the other. It is more of a case-specific issue (and maybe for some twisted problems where one of the two may fail for usually technical reasons). See this post for some related discussion, https://economics.stackexchange.com/a/14289/61.
...Or sometimes one may get a bit confused, for example, in the specific problem, one could momentarily stop and wonder &quot;what is the derivative of the Hamiltonian with respect to the state variable?&quot;
Well, it is what it appears to be: zero. Because
$$\frac{\partial \mathcal H}{\partial k}= \frac{\partial \lambda \dot k}{\partial k} = -\frac{\partial \lambda c}{\partial k} = 0,$$
because we do not differentiate the decision variable, or the multiplier, with respect to the state variable. Now, optimally, we have
$$\frac{\partial \mathcal H}{\partial k} = -\dot \lambda,$$
and so it follows that the multiplier is constant along the time axis, $\dot \lambda = 0$. Then for the other first-order condition, we have
$$\frac{\partial \mathcal H}{\partial c} = 0 \implies e^{-rt} \frac 1 c = \lambda.$$
Differentiating this with respect to time we get
$$-re^{-rt} \frac 1 c - e^{-rt} \frac{\dot c}{c^2} = 0 \implies \dot c = -rc,$$
which is what we get from HJB as &quot;policy&quot; function.
As for whether this is a maximum, it is, because the Hamiltonian is jointly concave in $c$ and $k$, see, https://economics.stackexchange.com/a/6063/61.