处理外部罐子中不存在的方法

时间:2017-12-15 17:59:12

标签: java

我有一个应用程序,我在其中引用外部库。在从这个库中的对象类型调用一个特定方法时,我的一些客户端遇到问题,因为他们在这个库的版本中没有这个方法。我试图捕获此异常并正确地向用户报告。所以我将调用包装在try / catch块中,但这并没有抓住它:

try
{
    cell.setRowspan(rowSpan);
}
catch (Exception  e)
{
    Throwable throwable = e.getCause();
    throw new Exception(throwable);
}

当我尝试调试问题时,eclipse只是打开了java.lang.reflect.InvocationTargetException clas。它不会进入catch块。我能在这里做些什么来正确地解决这个问题?

1 个答案:

答案 0 :(得分:-1)

import requests
import json

session = requests.Session()

loginUrl = "https://wedgfl.aquahawk.us/login"
loginHeaders = {
        "Host": "wedgfl.aquahawk.us",
        "Connection: keep-alive",
        "Accept": "application/json",
        "Origin": "https://wedgfl.aquahawk.us",
        "X-Requested-With": "XMLHttpRequest",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36",
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "Referer": "https://wedgfl.aquahawk.us/login",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "en-US,en;q=0.9",
}

loginData = {
    "username":"myemail@domain.tld",
    "password":"MySecretPassword"

}

#Data is posted as Json Data using json.dumps
loginResponse = session.post(loginUrl, data=json.dumps(loginData), headers=loginHeaders)
#If the above does not work try without json.dumps
loginResponse = session.post(loginUrl, data=loginData, headers=loginHeaders)
print(loginResponse)   #should print 200

#check if logged in 

verify = session.get("https://wedgfl.aquahawk.us/")
print(verify.text)