Or if you dont want to set the novars and nomacros options to ON, this also seems to return the correct error.

 Code:
? tryCommand("use c: '\\fileserver\share1'", 3)
? tryCommand("use c: '\\fileserver\share1'", 3)
? tryCommand("use c: '\\fileserver\share1'", 3)
get $

function tryCommand($command, $howoften, OPTIONAL $interval)
   DIM $i
   DIM $ERROR
   $i = 0
   if $howoften < 1 
      $tryCommand = -1
      return $tryCommand
   endif
   do
      $ = execute($command+" $$ERROR = @@error")
      if $ERROR = 0 
         $tryCommand = $ERROR
         return $ERROR
      endif
      if $interval <> ""
         sleep $interval
      endif
      $i = $i + 1
   until $i = $howoften
   $tryCommand = $ERROR
endfunction