Created
January 25, 2012 19:04
-
-
Save ldaniel/1677933 to your computer and use it in GitHub Desktop.
Tratando erros no Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void openFile(){ | |
try { | |
FileReader reader = new FileReader("arquivo.txt"); | |
int i=0; | |
while(i != -1){ | |
i = reader.read(); | |
System.out.println((char) i ); | |
} | |
reader.close(); | |
System.out.println("-> EOF"); | |
} catch (FileNotFoundException e) { | |
// acoes em caso de excecao do tipo "file not found" | |
} catch (IOException e) { | |
// acoes em caso de excecao de IO | |
} | |
finally { | |
// acoes finais que serao executadas independentemente | |
// de ter ocorrido uma exception | |
} | |
} | |
// ou ainda | |
public void doSomething() throws IOException, FileNotFoundException{ | |
// codigo aqui | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment