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])
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>
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.