0

I need code which could handling the exception and continue the process. but the error handling routine seems unable to get the correct error message:

without exception handling:

wsadmin>AdminControl.testConnection (SomeDataSource)

WAS7015E: Exception Running command: "AdminControl.testConnection (SomeDataSource)"
com.ibm.websphere.management.exception.AdminException
javax.management.MBeanException
java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: DSRA8000E: Java archive (JAR) or compressed files do not exist in the path or the required access is not allowed.  Path: /ojdbc6.jar

with exception handling:

wsadmin>try:
wsadmin>  AdminControl.testConnection (SomeDataSource)
wsadmin>except:
wsadmin>  typ,val,tb = sys.exc_info()
wsadmin>  print typ
wsadmin>  print val
wsadmin>  print tb

com.ibm.ws.scripting.ScriptingException
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
<traceback object at -1765990050>

Another version (although i believe there should be smarter way to perform it)

wsadmin>fname='${Server log folder}\SystemOut.log'
wsadmin>file=open(fname,'r')
wsadmin>junk=file.readlines()
wsadmin>file.seek(-1,1)
wsadmin>try:
wsadmin>  AdminControl.testConnection (SomeDataSource)
wsadmin>except:
wsadmin>  err='yes'
wsadmin>
wsadmin>file.seek(1,1)
wsadmin>if err='yes':
wsadmin>  msg=file.readlines()
wsadmin>  print 'Error: '.join(msg)

Seems i finally get the thing i want, although it is really ugly by skipping the entire error handling but directly getting the content of error log.

4

1 回答 1

0

我不知道为什么在 wsadmin jython 中会发生这种情况,但你可以试试这个:

    try:
     SomeDataSource = "Test"
     AdminControl.testConnection (SomeDataSource)
    except:
     typ,val,tb = sys.exc_info()[1]
     print typ
     print val
     print tb

有结果:

    wsadmin>try:
    wsadmin> SomeDataSource = "Test"
    wsadmin> AdminControl.testConnection (SomeDataSource)
    wsadmin>except:
    wsadmin> typ,val,tb = sys.exc_info()[1]
    wsadmin> print typ
    wsadmin> print val
    wsadmin> print tb
    wsadmin>
    WASX7015E: Exception running command: ""; exception information:
     com.ibm.ws.scripting.ScriptingException: AdminControl service not available

注意 sys.exc_info() [1]

问候

于 2014-01-14T20:22:14.257 回答