I made a couple simple functions that I would like to share that helps with debugging of long Mathcad Prime (circa v9) programs. (file attached)
I was making a VERY LONG convoluted program that called several sub-functions (in order to split it up). But it still had bugs by the time it was fully grown (don't we all;).
I made this function so that I could locate the errors before it happened. It is basically a logger that lets the program continue. It is better than a "return" statement in a few ways:
Notes:
P.S. Please forgive me if there is another post like this but there are lots to search though and I am not sure I used the right keywords. There are a few posts about writing data to file but this is a complete function you can cut and paste into your sheet (or include).
Neat.
Here's another method I've found helpful in hunting down the bugs once I know where they live ...
Mathcad Prime 10
Stuart
Hi @StuartBruff
Using "Try/On Error" is another way to handle errors. I mostly use them when I can expect an error as a normal course of calculations. I use the debug method when I am trying to find the error and I do not want to rewrite/reorganize the structure by adding Try statements—it is much easier to move the debug statement around.
@SPauliszyn wrote:
Hi @StuartBruff
Using "Try/On Error" is another way to handle errors. I mostly use them when I can expect an error as a normal course of calculations. I use the debug method when I am trying to find the error and I do not want to rewrite/reorganize the structure by adding Try statements—it is much easier to move the debug statement around.
I agree.
As I tend to keep many Mathcad worksheets within a single folder and often work on several worksheets in parallel, I'd probably add a file argument to your function to allow simultaneous use of different debug files.
A more generic problem, harking back to Mathsoft days, is the minimal debugging information available to a programmer/user. Mathcad 15 had, IMO, better facilities but was still wanting. It is challenging to know which part of a program/function has raised an error; the error messages don't chain, and the errors provide little contextual information - that's why I return the values in force at the point of error. The inability to query an error message within a worksheet is also limiting; for example, any error message is only available in tiny point (hard to read on a 4K monitor at 80% zoom), can't be copied, and can't be retrieved to a variable.
I'd also like a functional form of try-else. I dislike programs taking up unnecessary vertical space; a try(expression, error_response) form would allow, IMO, for a more readable and compact program on many occasions.
Stuart
I see.
@SPauliszyn wrote:
I see. Sorry this “debug” post doesn’t work out for you.
I don't think I said that; quite the opposite. Both the post and your debug function are certainly relevant and helpful. I was referring to Mathcad debugging in general, which I had hoped was clear from the context.
Stuart
That will work. Actually I use a more robust debug function that has an index parameter. It can be a string (tag), or an index. The data is kept in a vertical matrix in the single file so you don't clutter up your folder.