I am modifying a project made in classic asp with Visual Basic 6 and I need to catch an error.
Specifically, the error is generated by these lines:
dim strResult, split1, split2
strResult = FuncionQueDevuelveUnXML()
split1 = Split(strResult,"</a:AccessToken>")(0)
split2 = Split(split1,"<a:AccessToken>")(1)
The case where it fails that I would like to capture is when the tag does not existAccessToken
.
As you can see currently there is no control and the page generates an error 500 ( very ugly )
I know I could perform a InStr
to check if the tag exists:
if InStr(strResult,"<a:AccessToken>") < 1 Then
'No existe el tag
else
'Si existe el tag
end if
But I wanted to know if a can be done try catch
to catch any type of error.
Although not with try catch
itself but something similar, the truth is that I do not know if there is such a thing.
You should use the On Error statement. Something like that:
To enable error handling with the On Error statement you have 3 options:
When you have enabled error handling with one of these 3 options, once you have finished the block in which you want to handle errors (the code you would normally have in a try) you can (or rather should) use the On Error GoTo 0 statement to disable error handling.
You can find information about the On Error statement in the MSDN documentation: On Error Statement (Visual Basic)