Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ej3;
- /*
- ejemplo 3:
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class Ej3{
- public static void main(String[] args) {
- boolean ctr = true;
- while(ctr){
- try{
- Scanner r = new Scanner(System.in);
- int i = r.nextInt();
- ctr = false;
- }catch(InputMismatchException ex){
- ex.printStackTrace();
- }
- }
- }
- }
- - se puede tener muchos catch anidados
- ****************************
- se puede poner un solo catch que vea todas las exception
- ej: catch(exception ex){
- ...
- *********************************************
- ** propagacion de exception **
- public void doAlgo()throws InputMismatchException{ <-
- Scanner s = new Scanner (System.in);
- int i = s.nextInt();
- }
- public void doAlgoMas()throws InputMismatchException{
- doAlgo();
- }
- public void doAlgo3(){
- try{
- doAlgoMas();
- }catch(InputMismatchException ex){
- ...
- }
- }
- *************************************
- try{
- ...
- }catch(... ex){
- ...
- }catch(... ex2){
- ...
- }finally{ <- se puede cerrar el archivo
- try{
- ...
- }catch(...)
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement