¿Qué son? – tipos – manejo - ejemplos

Slides:



Advertisements
Presentaciones similares
Java nos ofrece System.out para escribir en pantalla, pero también tenemos System.in para leer. System.in es un objeto de una clase de java que se llama.
Advertisements

Ayudantía Pre-Actividad 5 Multimedios. Ayudantía Pre-Actividad 5 (1) creación de varias clases, y composición (2) manejo de threads (3) manejo de excepciones.
Exceptions y Assertions Introducción a la terminología Bloques: try, catch Uso de finally Bloques: try, catch, finally Categorías de Exceptions Excepciones.
Archivos de Texto. Introducción Los archivos son una secuencia de bits que se guarda en el disco duro. La ventaja de utilizar archivos es que los datos.
Curso de Java Capitulo 7: Continuación Poo Profesor:
EXCEPCIONES UNIDAD 5.
Programación Interactiva Manejo de Excepciones
Manejo de errores y excepciones
Lenguaje de programación Java
Herencia simple y multiple
Programación en Java Instructor:.
MANEJO DE EXCEPCIONES EN C++
Excepciones Las excepciones son señales (en forma de objeto) que se generan en ejecución en casos de errores, para que puedan ser gestionadas en el programa.
Arquitectura CLARO-TECNOTREE CAPITULO 4: Excepciones
Capitulo 4 Excepciones.
Siguiente Excepciones Introducción. AnteriorSiguiente Definición Una excepción es un evento que ocurre durante la ejecución de un programa que desestabiliza.
Informática II Prof. Dr. Gustavo Patiño MJ
RMI Remote Method Invocation
UNIVERSIDAD LATINA (UNILA) ENCAPSULACION Y HERENCIA
UNIVERSIDAD LATINA (UNILA)
EXCEPCIÓN DE ERRORES.
Excepciones y archivos Info 033. Exception El término Exception es la palabra corta para la frase "evento excepcional." Definition: Una excepción es un.
Control de excepciones
Manejo de excepciones en Java
INSTITUTO TECNOLOGICO DE TEHUACAN Ingeniería en sistemas computacionales Curso de apoyo a la titulación EXCEPCIONES EN JAVA Diciembre de 2008.
Clases y objetos La unidad fundamental de programación OO son las clases. Conjunto de métodos y semántica Qué se va a hacer POO Clase: que define la implementación.
Tema 6: Clases Antonio J. Sierra.
Manejo de Excepciones Agustín J. González ELO329.
UNIDAD 2 CLASES Y OBJETOS. CLASE Elementos cabecera y cuerpo de la clase. Cabecera: aporta información fundamental sobre la clase en sí y constituye de.
Tema 11: Excepciones Antonio J. Sierra.
Programación Orientada a Objetos Temario Excepciones – Definición. – Funcionalidad – Tipos de Excepciones – API de las Excepciones – Captura de Excepciones.
Computación II Unidad X Manejo de Excepciones. Presentación de la Unidad Objetivos: –Saber manejar situaciones inesperadas dentro de un programa –Comprender.
USO DE EXCEPCIONES EN JAVA LSC. Natalia Rodríguez Castellón.
SCJP SUN CERTIFIED PROGRAMMER FOR JAVA 6. SCJP 6.0 SEMANA CUATRO CONTROL DE FLUJOS, EXCEPCIONES Y ASERSIONES.
Programación orientada a objetos Capítulo 12 Manejo de errores.
Módulo 8: Manejo de Errores y Excepciones
Manejo de excepciones en Java ELO329: Diseño y Programación Orientados a Objetos Agustín J. González.
Programación Orientada a Objetos Unidad 4 Excepciones Universidad de Chile Departamento de Ciencias de la Computación.
ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 4 MANEJO DE EXCEPCIONES Y ERRORES.
Unidad III Manejo de Excepciones en Java y C++
Excepciones Unidad 5.
Sintaxis Completa los siguientes esquemas: Esquema de excepción Excepción Definición Tipos Implementación En el lenguaje Java, excepción es un tipo de.
INTRODUCCIÓN A JAVA. Índice ¿Qué es Java? La plataforma Java 2 La Máquina Virtual de Java Características principales ¿Qué ventajas tengo como desarrollador?
Metodología para solución de problemas
1 Manejo de Excepciones y otros Agustín J. González ELO-329.
Programación Interactiva Manejo de Excepciones Escuela de Ingeniería de Sistemas y Computación Facultad de Ingeniería Universidad del Valle.
Java.
Programación avanzada en Java Miguel Ángel Corella 26 de Septiembre de 2005.
Manejo de errores: Excepciones en Java
EI, Profesor Ramón Castro Liceaga Agosto de 2005 UNIVERSIDAD LATINA (UNILA) PROGRAMACION ORIENTADA A OBJETOS EN JAVA (Optativa) ESTRUCTURA DEL LENGUAJE.
Programación orientada a objetos Capítulo 12 Manejo de errores.
Tratamiento de excepciones
Manejo de errores: Excepciones en Java ELO329: Diseño y Programación Orientados a Objetos.
Desarrollo de lógica algorítmica.
MANEJO DE EXCEPCIONES. 21/11/2005 E.T.S de Ingenieros de Telecomunicacion.2 Índice ¿Qué es una excepción? Tipos de situaciones. Manejo de excepciones.
Excepciones definidas por el usuario Semana 7. Aprendizajes esperados Construye procedimientos almacenados, triggers de base de datos, cursores y funciones.
Metodología de Programación Ayudantía 4 lelagos.ublog.cl 2009.
Manejo Excepciones Profesor Elian Rojas Berroca 11/02/2015.
:: Prof. Yeniffer Peña Programación I Programación Orientada a Objetos Presentación.
Desarrollador Profesional de Juegos Programación III Unidad I Capturar Excepciones.
ECOM-6030 CAPÍTULO 7 EXCEPTION HANDLING Prof. Nelliud D. Torres © - Derechos Reservados.
Desarrollador Profesional de Juegos Programación III Unidad I Excepciones Tipos.
SCITMina | by Microsoft Bienvenidos Eduardo Daniel Tenorio Mayo Microsoft Student Partner Taller de Programación Orientada a Objetos Con C# Edgar Edel.
:: Prof. Yeniffer Peña Programación I Programación Orientada a Objetos Presentación.
Programación orientada a objetos La programación orientada a objetos o POO (OOP según sus siglas en inglés) es un paradigma de programación que usa objetos.
Fundamentos de Programación Departamento de Lenguajes y Sistemas Informáticos Práctica 4 Versión Diseño de tipos Igualdad, representación, código,
Manejo de Excepciones made by cristhian.. !!.  Errores que se pueden producir durante la ejecucion de una aplicacion y que podemos controlar o manejar.
Excepciones Diseño y manejo de excepciones Fundamentos de Programación Departamento de Lenguajes y Sistemas Informáticos Práctica 5 Versión
Programación en Java Introducción a Java. Reseña histórica Surge en 1991 por Sun Microsystems Desarrollado para electrodomésticos Se buscaba un código.
Programación en Java Introducción a Java. Reseña histórica Surge en 1991 por Sun Microsystems Desarrollado para electrodomésticos Se buscaba un código.
Transcripción de la presentación:

¿Qué son? – tipos – manejo - ejemplos Excepciones en java ¿Qué son? – tipos – manejo - ejemplos

¿Qué es una excepción? Es una condición anormal ocurrida durante la ejecución de un programa. No necesariamente es un error, sino más bien un comportamiento no adecuado o no permitido. A diferencia de otros lenguajes de programación orientados a objetos, Java incorpora la gestión de excepciones, a través de ciertas clases especiales.

Cuando ocurre una excepción, se crea un objeto que contiene toda la información acerca de ésta. El interpretador (JVM) debe encontrar el código para manejarla (lanzar la excepción). Si existe un código definido para el tipo de excepción, este código atrapa la excepción. Si no existe código definido para este tipo de excepción, el programa se termina.

Tipos de excepciones Trowable Exception Error Runtime Exception IOException EOFException NullPointerException FileNotFoundException IndexOutOfBoundsException MalformedURLException NegativeArraySizeException ArithmeticException

Manejador de excepciones Sirve para : Procesar solamente situaciones excepcionales donde un método no podría completar su tarea debido a que no posee el control. En proyectos grandes para manejar las excepciones de una manera uniforme en todo el proyecto. Simplifican los programas ya que se diferencia el código normal del código de tratamiento de errores. Se crean programas mas robustos ya que en muchos casos si no se trata la excepción el programa no compila.

PALABRAS CLAVE AL MANEJAR EXCEPCIONES try Catch throw throws Animated series of emerging circles (Intermediate) To reproduce the SmartArt on this slide, do the following: On the Home tab, in the Slides group, click Layout, and then click Blank. Also under Bevel, to the right of the Top list, in the Width box enter 30 pt. On the Insert tab, in the Illustrations group, click SmartArt. In the Choose a SmartArt Graphic dialog box, in the left pane, click Relationship. In the Relationship pane, click Basic Radial (eighth row, second option from the left), and then click OK to insert the graphic into the slide. Also under Bevel, to the right of the Top list, in the Height box enter 30 pt. On the Home tab, in the Font group, in the Font Size box enter 40 pt. and click Bold. On the slide, select the SmartArt graphic, and then click one of the arrows on the left border. In the Type your text here dialog box, in the top-level bullet, enter the text for the center circle of the graphic. In the second-level bullets, enter the text for all the other shapes in the SmartArt graphic. Position the top circle slightly towards the bottom of the slide. To reproduce the line effects on this slide, do the following: Press and hold CTRL and select each of the four lines connecting the circles in the SmartArt graphic. With the SmartArt graphic still selected, on the Design tab, in the Themes group, click Colors and select Median. On the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click Line Color in the left pane, and in the Line Color pane do the following: Under SmartArt Tools, on the Format tab, in the Size group, do the following: In the Shape Height box, enter 5”. In the Shape Width box, enter 7.5”. Click Gradient line. In the Type list, select Linear. Under SmartArt Tools, on the Format tab, in the Arrange group, click Align and then do the following: In the Direction list, select Linear Right (first row, fourth option from the left). Click Align to Slide. Under Gradient stops, click Add or Remove until two stops appear on the slider, then customize the gradient stops as follows: Click Align Center. Click Align Middle. Under SmartArt Tools, on the Design tab, in the SmartArt Styles group, click the More arrow at the SmartArt Styles gallery, and then under Best Match for Document select Intense Effect (the fifth option from the left). Select Stop 1 on the slider, and then do the following: In the Position box, enter 0%. On the Home tab, in the Font group, click the button next to Font Color, and then under Theme Colors select Black, Text 1 (first row, the second option from the left). Click the button next to Color, and then under Theme Colors click Black, Text 1 (first row, second option from the left). On the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click 3-D Format in the left pane, and in the 3-D Format pane, under Surface do the following: Select Stop 2 from the list, and then do the following: In the Stop position box, enter 100%. In the Material list, under Special Effect, select Soft Edge (second option from the left). In the Lighting list, under Neutral, select Harsh (first row, the fourth option from the left). In the Transparency box, enter 100%. Also in the Format Shape dialog box, click Line Style in the left pane, and in the Line Style pane do the following: In the Angle box, enter 30°. Press and hold CTRL, and select all five shapes in the SmartArt graphic, and then on the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click Shadow in the left pane, and in the Shadow pane do the following: In the Width box, enter 3.5 pt. In the Dash type list, select Round Dot (second option from the top). To reproduce the animation effects on this slide, do the following: In the Presets list, under Outer, select Offset Bottom (first row, the second option from the left). On the Animation tab, in the Advanced Animations group, click Animation Pane. In the Transparency box, enter 65%. On the slide, select the SmartArt graphic, and then on the Animations tab, in the Animation group, click the More arrow at the Effects Gallery and click More Entrance Effects. In the Change Entrance Effect dialog box, under Moderate, select Basic Zoom, and then click OK. In the Size box, enter 103%. In the Blur box, enter 9 pt. In the Angle box, enter 90°. In the Distance box, enter 3 pt. In the Animation group, click Effect Options and do the following: To reproduce the SmartArt effects on this slide, do the following: Under Direction, click In from Screen Center. On the slide, select the center circle in the SmartArt graphic, and then on the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click 3-D Format in the left pane, and in the 3-D Format pane do the following: Under Sequence, click One by one. In the Custom Animation task pane, expand the contents by clicking the double arrow under the zoom entrance effect, and then do the following: Select the first effect (zoom entrance effect), and in the Timing group, in the Start list, select With Previous. Under Bevel, in the Top list, under Bevel, select Circle (first row, the first option from the left). Select the second effect (zoom entrance effect). On the Animations tab, in the Animation group, click the More arrow at the Effects Gallery, and under Entrance, click Wipe, and click OK. Also under Bevel, to the right of the Top list, in the Width box enter 24 pt. Also under Bevel, to the right of the Top list, in the Height box enter 12 pt. On the slide, select the top circle in the SmartArt graphic, and then on the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click Fill in the left pane, and in the Fill pane do the following: With the second effect (now wipe effect) still selected, do the following: In the Animation group, click Effect Options, and then under Direction, select From Bottom. Click Solid fill. In the Timing group, in the Delay list, enter 00.50. Click the button next to Color, and then under Theme Colors select Orange, Accent 2 (first row, the sixth option from the left) In the Timing group, in the Duration list, enter 00.50. Also in the Format Shape dialog box, click 3-D Format in the left pane, and in the 3-D Format pane do the following: Select the fourth effect (zoom entrance effect). On the Animations tab, in the Animation group, click the More arrow at the Effects Gallery, and under Entrance, click Wipe, and click OK. With the fourth effect (now wipe effect) still selected, do the following: Also under Bevel, to the right of the Top list, in the Width box enter 20 pt. In the Animation group, click Effect Options, and then under Direction, select From Left. Also under Bevel, to the right of the Top list, in the Height box enter 15 pt. Press and hold SHIFT, and drag a corner sizing handle towards the center of this circle to make it smaller. On the Home tab, in the Font group, in the Font Size box enter 20 pt. Position the top circle slightly over to the right 0.5”. Select the sixth effect (zoom entrance effect). On the Animations tab, in the Animation group, click the More arrow at the Effects Gallery, and under Entrance, click Wipe, and click OK. Select the right circle in the SmartArt graphic, and then on the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click Fill in the left pane, and in the Fill pane do the following: With the sixth effect (now wipe effect) still selected, do the following: Click the button next to Color, and then Theme Colors select Gold, Accent 4 (first row, the eighth option from the left) Select the eighth effect (zoom entrance effect). On the Animations tab, in the Animation group, click the More arrow at the Effects Gallery, and under Entrance, click Wipe, and click OK. With the eighth effect (now wipe effect) still selected, do the following: In the Animation group, click Effect Options, and then under Direction, select From Right. On the Home tab, in the Font group, in the Font Size box enter 28 pt. Position the right circle slightly towards the upper right corner of the slide. One the slide, select the bottom circle in the SmartArt graphic, and then on the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click Fill in the left pane, and in the Fill pane do the following: To reproduce the background on this slide, do the following: In the Color list, under Theme Colors select Green, Accent 5 (first row, the ninth option from the left) Right-click the slide background area, and then click Format Background. In the Format Background dialog box, click Fill in the left pane, select Gradient fill in the Fill pane, and then do the following: In the Type list, select Radial. In the Direction, list click From Center (third option from the left) Under Bevel, in the Top list, select Circle (first row, the first option from the left). in the drop-down list. Press and hold SHIFT, and drag a corner sizing handle away from the center of this circle to make it larger. Click the button next to Color, and then under Theme Colors click Black, Text 1, Lighter 35% (third row, second option from the left). Drag the circle slightly toward the right edge of the slide. On the slide, select the left circle in the SmartArt graphic, and then on the Home tab, in the bottom right corner of the Drawing group, click the Format Shape dialog box launcher. In the Format Shape dialog box, click Fill in the left pane, and in the Fill pane do the following: Select Stop 2 on the slider, and then do the following: In the Position box, enter 100%. In the Color list, under Theme Colors select Olive Green, Accent 3 (first row, the seventh option from the left) PALABRAS CLAVE AL MANEJAR EXCEPCIONES

try Entre las llaves de try escribiremos el código que hará funcional nuestro programa. Las instrucciones contenidas en un bloque try, lanzarán la excepción si ésta ocurre.

De esta manera yo puedo controlar a la Excepción De esta manera yo puedo controlar a la Excepción. Si no se utilizara el bloque Try, se termina la aplicación y nos sale un error en la consola.

Al no utilizar try , al momento de correr la aplicación va a generarse una Excepción y como no la manejamos, se corta la aplicación

Catch Para capturar la excepción que puede generar este código necesitaremos de esta otra instrucción. Se debe escribir inmediatamente después del bloque try. Puede haber varios bloques catch para un bloque try, y cada bloque catch manejará un tipo de excepción. Es decir, la sentencia “Catch” atrapa la excepción lanzada y la maneja.

De esta manera podemos impedir que la aplicación se corte, al encontrarse con un ‘comportamiento no adecuado’. En este ejemplo vemos como el catch maneja la Excepción y la imprime en la consola, siempre y cuando ésta se genere.

Cómo definir excepciones personalizadas A pesar de la gran cantidad de clases que Java posee para el manejo de excepciones, se permite la creación de excepciones propias al programador. Normalmente se crean nuevas excepciones cuando las clases que posee Java no contemplan el manejo de una situación anómala particular. Para crear las excepciones propias se hereda de la clase Exception o de una de sus subclases.

definir excepciones personalizadas Al definir Excepciones personalizadas, es conveniente generar un paquete nuevo.

definir excepciones personalizadas Pasos para crear una Excepción propia : Dentro del paquete de Excepciones generar una nueva clase con el nombre deseado. Se define para esta nueva clase que herede de Throwable o generalmente de Exception.

throws En ciertos casos, cuando un método puede generar una situación anómala, y no se desea manipular la excepción en el código del propio método, es posible que se pase o se “relance” la excepción al método invocador, para ello se utiliza la sentencia throws. Dicha sentencia obliga a quién invoque al método, usar un bloque try / catch o propagarlo con otro throw.

throw La sentencia throw (lanzar) se puede emplear para indicar que ha ocurrido una excepción, particularmente cuando se quiere lanzar una excepción propia. throw requiere un simple argumento: un objeto de la clase Throwable, esta clase tiene dos subclases principales: Exception y Error.

Fin! Juan Manuel Ruiz - 2012