Exception catching in loop -- Index Out of Range

Very basic coding question: I have a simple loop that performs an area calculation on a series of waves with a similar root name incremented by a value. There are some missing waves, however, which throw an Index Out of Range error in the middle of the loop and shut everything down. I'd like to add a line that basically says 'if this error is encountered, index+=1' and runs it again. How do I do that?
In the database I might have a collection of waves something like: Basename0, Basename1, Basename3. So, when Basename2 is used, the loop fails.


here's the code:

function AreaU()

variable numWave=40
variable index = 0
variable timeBegin = 1
variable timeEnd = 10

Make/O/N = (numWave) AreaWave

do

AreaWave[index] = area ($("Basename"+num2istr(index)) , timeBegin, timeEnd)
index += 1

while (index <= numWave)

end



Thanks!
Check for the existence of the wave before you call the area function. Use the waveexists function.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Like this:
function AreaU()

    variable numWave=40
    variable index = 0
    variable timeBegin = 1
    variable timeEnd = 10

    Make/O/N = (numWave) AreaWave

    do
        WAVE/Z w = $("Basename"+num2istr(index)
        if (WaveExists(w)
            AreaWave[index] = area (w , timeBegin, timeEnd)
        endif
        index += 1

    while (index <= numWave)

end

But now you have an infinite loop. How about a slightly different approach:
function AreaU()

    variable numWave=40
    variable index = 0
    variable timeBegin = 1
    variable timeEnd = 10

    Make/O/N = (numWave) AreaWave
    String wlist = WaveList("Basename*", ";", "")
    Variable nwaves = ItemsInList(wlist)
    Variable i
    for (i = 0; i < nwaves; i++)
        WAVE w = $StringFromList(i, wlist)  // could go directly in the call to area, I find this more readable
        AreaWave[index] = area (w , timeBegin, timeEnd)
        index += 1

    endfor

end


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com