Exception Handling in WSAdmin Scripts

Posted on 01/23/2009 , Alexander Ananiev, 2 Comments ( Add )

Using AdminTask in wsadmin often results in getting ugly stack traces. In fact, AdminTask always produces a full java stack trace even when the error is fairly innocuous (e.g., a resource name was mistyped). The stack trace in this situation is pretty useless; it could actually confuse operations staff as it might be interpreted as a problem in IBM code.

It is, in fact, quite easy to deal with this situation in Jython and suppress the annoying stack trace:


import sys
from com.ibm.ws.scripting import ScriptingException
...
    try:
        AdminTask....
    except ScriptingException:
        # note that we can't use "as" because of python 2.1 version, have to use sys
        print "Error:\n"+str(sys.exc_info()[1])

2 Responses to “Exception Handling in WSAdmin Scripts”

#35103 | November 18th, 2009 | Bob Gibson

Your indentation is broken. You should also make use of the exception type(i.e., sys.exc_info()[ 0 ]). For example:

wsadmin>try :
wsadmin> AdminTask.unknownMethod( ‘Parameter’ )
wsadmin>except :
wsadmin> ( kind, value ) = sys.exc_info()[ :2 ]
wsadmin> ( kind, value ) = str( kind ), str( value )
wsadmin> print ‘Exception type: ‘ + kind
wsadmin> print ‘Exception value: ‘ + value
wsadmin>
Exception type: exceptions.AttributeError
Exception value: unknownMethod
wsadmin>

#35104 | November 19th, 2009 | Alexander Ananiev

Bob, thanks for the tip. Here we’re trying to handle WAS-related exceptions only to avoid full Java trace. Therefore, it is safer to catch ScriptingException first as opposed to catching everything and then sorting through different exception types.

Leave a Reply

Name

Mail

Website

Your Comment

Most Popular Posts

Recent Tweets

Recent Posts

Blog Categories

Blog Archives