2

Is there a way to retrieve the output of a function that did not complete properly?

For instance, a (non global) variable that was correctly computed by a function but that couldn't be saved properly because of syntax errors.

1 Answer 1

6

In principle, you can't look into a function once the program has stopped with an error. (That's why I often try to avoid functions.)

However, you can achieve what you want by entering debugging mode, using the dbstop function to set a breakpoint:

The dbstop function is used to temporarily stop the execution of a program and give the user an opportunity to examine the local workspace.

In particular, typing

dbstop if error

in the command window before running your code will make it stop at the point that caused the error and look at the variables within that function.

To restore normal behaviour you need the dbclear function. Type

dbclear if error

to remove the previously set breakpoint, or

dbclear all

to remove all breakpoints.

Sign up to request clarification or add additional context in comments.

2 Comments

I will definitely use this from now on. It's very frustrating to run a code for 8 days and realize once it crashed that the output must be somewhere in the memory, just nowhere to be found.
I know what you mean... Functions hide all their internal data. That's often good, but sometimes frustrating. I'd rather have everything in sight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.