Array List IndexOutOfBounds

I have a list

def txtElem = ['4', '5', '5.5', '6', '6.5', '7']

I am trying to iterate through the list and verifying that current element is smaller than the next element. I am using the following for loop

for (int i = 0; i < txtElem.size(); i++) {
   	try {
		if (Double.parseDouble(txtElem.get(i)) > Double.parseDouble(txtElem.get(i+1))) {
			assert 1 == 2;
		}
	} catch(Exception e) {
		KeywordUtil.logInfo("End of list reached")	
}

I am failing the test if current element is greater than the next element. The loop works perfectly until the second to last element, but when ā€˜iā€™ becomes the last element, the loop throws IndexOutOfBounds exception (rightly so) when trying to access txtElem.get(i+1)

I tried to add the try catch block, but still the loop throws same exception.

Does someone knows how to avoid this exception?

import com.kms.katalon.core.util.KeywordUtil

def txtElem = ['4', '5', '5.5', '6', '6.5', '7']

double previous = 0.0
for (int i = 0; i < txtElem.size(); i++) {
	double current = Double.parseDouble(txtElem.get(i))
	if (previous >= current) {
		KeywordUtil.markFailed("privious=${previous}, current=${current} not in order")
	}
	previous = current
}