Like the title says, I want to be able to stop the code at a specific location and have it halt safely. I cannot find a command to do it like for example in FORTRAN there is the stop command.
The function error('error message');
will exit your program and print the error message to the console.
There is break
to exit a loop and return
to return to the invoking function or keyboard/promt.
Here is a function that does it (without printing any message):
function stoprun()
ms.message='';
ms.stack = dbstack('-completenames');
ms.stack(1:end) = [];
ds = dbstatus();
stoponerror = any(strcmp('error', {ds.cond}));
setappdata(0, 'dberrorkeep', stoponerror);
dbclear error
error(ms);
end
you can use "return" and it will "return control to the invoking function before it reaches the end of the function", which for the main program means exiting the program.
-
$\begingroup$ What happen in the case that you don't have a function? $\endgroup$ – nicoguaro♦ Oct 7 '14 at 19:11