[gradsusr] Error Handling

Stephen McMillan smcmillan at planalytics.com
Sat Nov 13 22:17:34 EST 2010


Hi Andrew,
Yes there is.  Here's one way that works for me, in a situation where I
search for an available dataset source until I find one (just the applicable
part of script shown).  The CheckFile function shown will also handle a
situation where one file was opened successfully, but you also want to check
a second file needed for the operation
:
  datfile.1='http://source1....'
  datfile.2='http://source2....'
  datfile.3='http://source3....'
  n=1
  while(n<=3);#search for a valid file, exit loop when found
    'sdfopen 'datfile.n
    validfile=CheckFile(1);#assumes no previous files open, else use
appropriate number
    if(validfile)
      say 'Using 'datfile.n;break
    else
      say datfile.n' not available'
      n=n+1
    endif
  endwhile
  if(validfile)
    say 'Continuing operation...'
  else
    say 'Aborting operation!'
    exit
  endif
# if validfile=1, then continue operation....

function CheckFile(filenum)
#returns 1=true if data file is valid/open, else 0=false
  'q file 'filenum
  info=sublin(result,1)
  if(filenum=1);qa=substr(info,1,13);endif
  if(filenum=2);qa=substr(info,1,16);endif
  if(qa='No Files Open'|qa='QUERY FILE Error')
    return 0
  else
    return 1
  endif
return

Perhaps code similar to above will work for you.  Good luck.
Stephen McMillan

On Sat, Nov 13, 2010 at 3:38 AM, Andrew Revering <andy at f5data.com> wrote:

>  Is there a way to handle errors in grads scripts?
>
> For example… I'm opening files in the scripts… If a file does not exist,
> I'd like it to realize that and skip it and continue on.
>
>
>
>
>
>
>
> Andrew Revering
>
> Convective Development, Inc.
>
> http://www.convectivedevelopment.com/
>
>
>
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>

***************************************************
The information contained in this e-mail message 
is intended only for the use of the recipient(s) 
named above and may contain information that is 
privileged, confidential, and/or proprietary. 
If you are not the intended recipient, you may not
review, copy or distribute this message. If you have
received this communication in error, please notify 
the sender immediately by e-mail, and delete the original message.
***************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20101113/97c90d2b/attachment-0003.html 


More information about the gradsusr mailing list