Hallo,
bin am Programmieren und habe mich gerade gefragt, wie ich einen Try/Catch Block am sinnvollsten platziere.
Hab jetzt mal 3 Beispiele aufgeführt. Welche Methode wäre die bessere/saubere Lösung oder gibt es vllt. auch noch eine andere bessere.
bin am Programmieren und habe mich gerade gefragt, wie ich einen Try/Catch Block am sinnvollsten platziere.
Hab jetzt mal 3 Beispiele aufgeführt. Welche Methode wäre die bessere/saubere Lösung oder gibt es vllt. auch noch eine andere bessere.
Java:
public void method1()
{
try{
TestClass t = getStream(); // Methode wirft Exception
t.doSomething();
t.doMoreSomething();
}
catch (MeineException e){
// handle Exception
}
... // weiterer Code
}
public void method2()
{
TestClass t;
try{
t = getStream(); // Methode wirft Exception
}
catch (MeineException e){
// handle Exception
}
t.doSomething();
t.doMoreSomething();
... // weitere Code
}
public void method3()
{
try{
TestClass t = getStream(); // Methode wirft Exception
t.doSomething();
t.doMoreSomething();
... // weitere Code
}
catch (MeineException e){
// handle Exception
}
}
Zuletzt bearbeitet: