Question: how to check for fopen() status?

Maple help pages are terrible.  Sorry, but this is true.

I am looking for one example of how one is supposed to open a file and correctly check that the open was successful and no error occured, all done in code. As in a script.

All what help in fopen says is that if this and that, it generates an error.

            "

OK. But to check for this in code? Why not show an example? the help page on iostatus just lists possible errors. Again, not a SINGLE example of actual Maple code showing how to actually check or handle an error. It just says to call iostatus() and shows the output without an example of what to do next and what to check for.

Lets say one does this:


fileName := "C:\\foo.txt";
fd       := fopen(fileName,WRITE):

Now what? How to check the above was successful? Do I need a trap and catch? catch what? Do I need to check for fd being greater or equal to zero and also use trap in addition? And if an error happens, how to know what it is? How to to format the message, etc.. all in CODE (not interactive) and not by saying just look at the screen and see if there is an error message.

Spend 30 minutes in the help pages and could not find ONE example that shows how to actually check for errors.

I have no idea who writes Maple helps pages, but I find the help pages useless most of the time.

Compare the help for linux fopen for example, where is gives exact details of how to handle the error and find the exact error, all in code.

 

Please Wait...