Capture Error Code in a Variable

I have a BASIC script running which sends data from the SD card to an FTP server. Once the file is copied successfully, I erase the file from the SD card. I am doing this round robin style, so eventually the loop will come back around and attempt to copy the file from the same location again. But if I haven’t put a new file there yet, it will throw an Error and write that to the console.

The console might look something like:
"IO Error (33) 86: ERASE “/usr/sdext/Test”

When such an error occurs, I want to write it to a separate log file, and push that file to the server as well. Right now I am just able to write the timestamp and error code. What I would like to do is copy that console output.

So, is that console output saved in a variable somewhere, or is there a straight forward way to get it into a string?

Thanks in advance!

Topic closed due to inactivity.