Duvida em parar o while dentro for[RESOLVIDO]

Ah, o bloco finally

class B{ public int doIt(){ try{ return 1; }catch(Exception e){ return 2; }finally{ return 3; } } public static void main(String [] args){ int i = 0; B b = new B(); i = b.doIt(); System.out.println(i); } }

Sempre será impresso 3

Se bem que isso gera um belo warning!

[quote=peczenyj]Ah, o bloco finally

Sempre será impresso 3

Se bem que isso gera um belo warning![/quote]

Não tive warning aqui.

Nem mesmo com isso:

public int doIt() { try { try { return 1; } catch (Exception e) { return 2; } finally { return 3; } } catch (Exception e) { try { return 4; } catch (Exception e2) { return 5; } finally { return 6; } } finally { try { return 7; } catch (Exception e) { return 8; } finally { return 9; } } } Substituindo no teu código, adivinha o que imprime!

O legal é que ele passa pelo 1, 3, 7, e termina no 9, que é o último que vale. returns em qualquer outro lugar só dá unreacheable statement