Im StackTrace "zurückgehen"

Hallo,

der Vorteil der Exceptions wäre halt, dass du die abfangen kannst, wann und (fast) wo du willst. Und natürlich wären das (je nach Größe / Menüs des Programms) einige try-catch, das müsste man halt mal durchplanen. Aber ich denke, dass dies durchaus eine Option darstellen könnte.

Gruß
BK
 
Exceptions sind eigentlich dazu da um Fehler-Fälle darzustellen und nicht um ein Programm zu steuern.

Bevor du dir die Arbeit machst und dafür Exceptions einfallen lässt, solltest du eher dein Konzept überdenken.

Gruß

Sascha
 
Irgendwie peintlich, das mir die Idee erst vorhin gekommen ist, aber wie wäre es, wenn ich das ganze per Variable steuern würde?
Gemäß meinen Beispiels würde das dann ungefähr so aussehen:

Java:
public class HandleTelnetCon extends Thread
{
	private static final String LINE_WRAPPLER = System.getProperty("line.separator");

	private static final byte LOC_LOGIN = -128;
	private static final byte LOC_START_MENU = -127;

	private static final byte STANDART_LOC = LOC_LOGIN;

	private static final byte loc;

	public void run()
	{
		loc = STANDART_LOC;

		switch(loc)
		{
			case(lOC_LOGIN):
				login();
			break;

			case(LOC_START_MENU):
				menu();
			break;

			default:
				loc = STANDART_LOC;
			break;
	}
	public static void login()
	{
		String username;
		String password;
 		
		write("Username:" + LINE_WRAPPLER)
        	username = read();        

		write(LINE_WRAPPLER + "Password:" + LINE_WRAPPLER)
		password = read();
		
		if(loginCorrect(username, password))
			loc = LOC_MENU;
	}
	public static void menu()
	{
		write("0) Do Something"+ LINE_WRAPPLER);
		write("1) Do Something other" + LINE_WRAPPLER);
		write("2) Go Back" + LINE_WRAPPLER);
 
		try
		{
			byte input = Integer.parseInt(read());
 			if(input == 0)
			{
 
			}
			else if(input == 1)
			{
 
			}
			else if(input == 2)
			{
				loc = LOC_LOGIN;
			}
	        }
        	catch(NumberFormatException e) {}
	}
}

Der Vorteil wäre, ich umgehe das Problem mit dem Stack, und erspaare mir Schleifen um nach Fehlerfällen zu testen.
Was haltet ihr davon?
 

Neue Beiträge

Zurück