Forum Discussion
Mack_Hanson_107
Nimbostratus
Oct 27, 2005Error Handling, Test condition for variables
Is there some way to trap errors, so that the end-user doesn't experience pain? Whenever I refer to variable that isn't yet instantiated, BIGIP returns null, which in browser results in a JavaScript popup box that says "Document has no data." How do I check to see if a variable is valid without getting a BIGIP error? Is there a test condition?
My line '[session lookup ssl $sslsessionid]' is throwing errors when it can't find the session variable $sslsessionid.
when HTTP_REQUEST {
set uri_path [HTTP::uri]
if {[regexp {^(/login)(.)*?$} $uri_path] == 1} {
set ssl session id, in the website login section
set sslsessionid [SSL::sessionid]
}
}
when HTTP_RESPONSE {
retrieve previously stored ssl session id, from any website section
set sslid [session lookup ssl $sslsessionid]
}
- There are several ways you can avoid this runtime error from occuring.1. Force set the variable to an empty string in the HTTP_REQUEST event and check if it's not an empty string in the HTTP_RESPONSE event.
2. Use the "info exists" command to check if the variable is defined before trying to access it.when HTTP_REQUEST { set uri_path [HTTP::uri] set sslsessionid "" if {[regexp {^(/login)(.)*?$} $uri_path] == 1} { set ssl session id, in the website login section set sslsessionid [SSL::sessionid] } } when HTTP_RESPONSE { retrieve previously stored ssl session id, from any website section if { "" ne $sslsessionid } { set sslid [session lookup ssl $sslsessionid] } }
when HTTP_REQUEST { set uri_path [HTTP::uri] if {[regexp {^(/login)(.)*?$} $uri_path] == 1} { set ssl session id, in the website login section set sslsessionid [SSL::sessionid] } } when HTTP_RESPONSE { retrieve previously stored ssl session id, from any website section if { [info exists sslsessionid] and {"" ne $sslsessionid} } { set sslid [session lookup ssl $sslsessionid] } }
- Mack_Hanson_107
Nimbostratus
This is more what I had in mind. It works great. I've been using it for a while now.if { [catch { try some operation } ] == 1 } { handle the error }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects