Abort the installation wizard if a runtime exception happens

This commit is contained in:
snowleo 2011-10-26 19:46:40 +02:00
parent 48f8eb9788
commit 5641b1173c
2 changed files with 43 additions and 23 deletions

View file

@ -71,6 +71,8 @@ public abstract class AbstractState
abort(); abort();
return null; return null;
} }
try
{
final boolean found = reactOnAnswer(trimmedAnswer); final boolean found = reactOnAnswer(trimmedAnswer);
if (found) if (found)
{ {
@ -82,6 +84,12 @@ public abstract class AbstractState
return this; return this;
} }
} }
catch (RuntimeException ex)
{
sender.sendMessage(ex.toString());
return this;
}
}
/** /**
* Do something based on the answer, that the user gave. * Do something based on the answer, that the user gave.

View file

@ -32,15 +32,19 @@ public class StateMachine extends WorkListener
} }
public MachineResult askQuestion() public MachineResult askQuestion()
{
try
{ {
while (current.guessAnswer()) while (current.guessAnswer())
{ {
current = current.getNextState(); current = current.getNextState();
if (current == null) if (current == null)
{ {
result = MachineResult.DONE; result = MachineResult.DONE;
break; break;
} }
} }
if (current != null) if (current != null)
{ {
@ -50,6 +54,13 @@ public class StateMachine extends WorkListener
} }
result = MachineResult.WAIT; result = MachineResult.WAIT;
} }
}
catch (RuntimeException ex)
{
player.sendMessage(ex.getMessage());
finish();
result = MachineResult.ABORT;
}
return result; return result;
} }
@ -135,6 +146,7 @@ public class StateMachine extends WorkListener
private void finish() private void finish()
{ {
current = null;
iterator = null; iterator = null;
states.clear(); states.clear();
getPlugin().getServer().getPluginManager().callEvent(new InstallationFinishedEvent()); getPlugin().getServer().getPluginManager().callEvent(new InstallationFinishedEvent());