Not a member of GistPad yet?
Sign Up,
it unlocks many cool features!
- package maven_vsc;
- /*
- Vamos a estudiar como se propagan excepciones en codigo java
- se utiliza la palabra reservada "throws"
- en este caso el metodo no maneja la excepcion, sino que la envia al metodo que le llama
- El metodo que no maneja la excepcion es "calcularDivision"
- El metodo que le llama es "main"
- */
- public class App07 {
- private int dividendo;
- private int divisor;
- private float resultado;
- private boolean finaliza;
- public App07(int numeroUno, int numeroDos) {
- this.dividendo = numeroUno;
- this.divisor = numeroDos;
- this.resultado = 0.0f;
- this.error = "Debe introducir un numero que no sea cero";
- this.finaliza = false;
- }
- public void calcularDivision() {
- // if (this.divisor != 0) {
- this.resultado = (float) this.dividendo / this.divisor;
- // this.finaliza = true;
- // } else if (this.divisor == 0) {
- // throw new ArithmeticException(this.error);
- // }
- }
- App07 objeto = new App07(6, 10);
- try {
- objeto.calcularDivision();
- }
- finally{
- }
- }
- }
RAW Paste Data
Copied
