diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index d7c79c6c7..7653da444 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -403,7 +403,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { */ public synchronized void login() throws XMPPException, SmackException, IOException { if (isAnonymous()) { - throwNotConnectedExceptionIfAppropriate(); + throwNotConnectedExceptionIfAppropriate("Did you call connect() before login()?"); throwAlreadyLoggedInExceptionIfAppropriate(); loginAnonymously(); } else { @@ -584,8 +584,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException { + throwNotConnectedExceptionIfAppropriate(null); + } + + protected void throwNotConnectedExceptionIfAppropriate(String optionalHint) throws NotConnectedException { if (!isConnected()) { - throw new NotConnectedException(); + throw new NotConnectedException(optionalHint); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java index 1a2fd3f76..7187c6b0d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java @@ -1,6 +1,6 @@ /** * - * Copyright 2014 Florian Schmaus + * Copyright 2014-2015 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -152,7 +152,12 @@ public class SmackException extends Exception { private static final long serialVersionUID = 9197980400776001173L; public NotConnectedException() { - super("Client is not, or no longer, connected"); + this(null); + } + + public NotConnectedException(String optionalHint) { + super("Client is not, or no longer, connected." + + (optionalHint != null ? ' ' + optionalHint : "")); } }