0
我拋出一個異常,並像一些消息:拋出異常並獲得E無效
public static ILSResponseEmailLookUPBO getILSUserAccounts(Resources res,
String email) throws TripLoggerCustomException,
TripLoggerUnexpectedErrorException {
String resp = null;
String lookupURL;
try {
lookupURL = TripLoggerConstants.ServerConstants.ILS_LOOKUP_URL
+ URLEncoder.encode(email, "UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new TripLoggerCustomException(
res.getString(R.string.error_try_again));
}
try {
resp = ConnectionManager.getInstance().httpRequest(lookupURL,
TripLoggerConstants.RequestMethods.GET);
} catch (IOException e) {
if (e.getMessage().equals(
res.getString(R.string.network_unreachable))
|| e.getMessage().equals(
res.getString(R.string.host_unresolved))) {
throw new TripLoggerCustomException(
res.getString(R.string.network_not_reachable));
} else {
throw new TripLoggerCustomException(
res.getString(R.string.email_notfound_ils));
}
}
我這裏還有一部分執行。 我的異常類是:
public class TripLoggerCustomException extends Exception {
private String customMessage;
private static final long serialVersionUID = 1L;
public TripLoggerCustomException() {
super();
}
public TripLoggerCustomException(String message) {
super(message);
this.customMessage = (message == null ? "" : message);
}
public String getCustomMessage() {
return this.customMessage;
}
public void setCustomMessage(String customMessage) {
this.customMessage = customMessage;
}
}
這裏我捕獲這個異常:
private void manageLookUpActions(final String emailID) {
new Thread() {
public void run() {
try {
listILSAccounts = ILSLookupEmailBL.getILSUserAccounts(
getResources(), emailID);
} catch (TripLoggerCustomException e) {
dismissProgressBar();
handleException(e.getMessage());
return;
} catch (TripLoggerUnexpectedErrorException e) {
dismissProgressBar();
handleException(e.getMessage());
return;
}
}
}.start();
}
,但在這裏的TripLoggerCustomException e
美中不足的是null
。爲什麼誰能幫助我?
我相信這是不可能的。如果該異常爲空,那麼系統永遠不會知道它是「TripLoggerCustomException」類型。你是否在這一行中得到一個NullPointer異常:'handleException(e.getMessage());'。你可以嘗試添加一個全局'} catch(Exception e){}'來查看它是否在那裏結束? –
@JeffreyKlardie沒有發生空指針異常,它完全進入TripLoggerCustomException catch塊,但問題是「e」在TripLoggerCustomException的catch塊中爲null。 – user2106897
那麼,如果'e'確實爲null,則'e.getMessage()'將導致NullPointerException。我非常肯定,在這一點上,e是無效的。 –