<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es">
	<id>https://wiki.cifprodolfoucha.es/index.php?action=history&amp;feed=atom&amp;title=Posible_soluci%C3%B3n_Excepciones_Ejercicio_2</id>
	<title>Posible solución Excepciones Ejercicio 2 - Historial de revisiones</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.cifprodolfoucha.es/index.php?action=history&amp;feed=atom&amp;title=Posible_soluci%C3%B3n_Excepciones_Ejercicio_2"/>
	<link rel="alternate" type="text/html" href="https://wiki.cifprodolfoucha.es/index.php?title=Posible_soluci%C3%B3n_Excepciones_Ejercicio_2&amp;action=history"/>
	<updated>2026-10-17T06:08:52Z</updated>
	<subtitle>Historial de revisiones de esta página en el wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://wiki.cifprodolfoucha.es/index.php?title=Posible_soluci%C3%B3n_Excepciones_Ejercicio_2&amp;diff=4895&amp;oldid=prev</id>
		<title>Wiki: Página creada con «&#039;&#039;&#039;Clase LimitesException&#039;&#039;&#039; ::&lt;syntaxhighlight lang=&quot;java&quot; line enclose=&quot;div&quot; highlight=&quot;&quot; &gt; package EjerciciosPOO.excepciones.ejercicio2;  /**  *  * @author clase  */ pub...»</title>
		<link rel="alternate" type="text/html" href="https://wiki.cifprodolfoucha.es/index.php?title=Posible_soluci%C3%B3n_Excepciones_Ejercicio_2&amp;diff=4895&amp;oldid=prev"/>
		<updated>2018-01-09T20:12:18Z</updated>

		<summary type="html">&lt;p&gt;Página creada con «&amp;#039;&amp;#039;&amp;#039;Clase LimitesException&amp;#039;&amp;#039;&amp;#039; ::&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot; line enclose=&amp;quot;div&amp;quot; highlight=&amp;quot;&amp;quot; &amp;gt; package EjerciciosPOO.excepciones.ejercicio2;  &lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;*  *  * @author clase: &lt;/span&gt; pub...»&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Página nueva&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Clase LimitesException&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
::&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot; line enclose=&amp;quot;div&amp;quot; highlight=&amp;quot;&amp;quot; &amp;gt;&lt;br /&gt;
package EjerciciosPOO.excepciones.ejercicio2;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 *&lt;br /&gt;
 * @author clase&lt;br /&gt;
 */&lt;br /&gt;
public class LimitesException extends Exception {&lt;br /&gt;
    &lt;br /&gt;
    public LimitesException(String msg){&lt;br /&gt;
        super(msg);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Clase Lectura&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
::&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot; line enclose=&amp;quot;div&amp;quot; highlight=&amp;quot;&amp;quot; &amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * To change this license header, choose License Headers in Project Properties.&lt;br /&gt;
 * To change this template file, choose Tools | Templates&lt;br /&gt;
 * and open the template in the editor.&lt;br /&gt;
 */&lt;br /&gt;
package EjerciciosPOO.excepciones.ejercicio2;&lt;br /&gt;
&lt;br /&gt;
import java.util.InputMismatchException;&lt;br /&gt;
import java.util.NoSuchElementException;&lt;br /&gt;
import java.util.Scanner;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 *&lt;br /&gt;
 * @author clase&lt;br /&gt;
 */&lt;br /&gt;
public class Lectura {&lt;br /&gt;
    private static Scanner sc=new Scanner(System.in);&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    public static byte leerEntero() throws LimitesException,Exception{  &lt;br /&gt;
        System.out.println(&amp;quot;Introduce un número:&amp;quot;);&lt;br /&gt;
        int numero = sc.nextInt();  // Usamos nextInt para que no lance una excepcion si el número es mayor que 255&lt;br /&gt;
        if (numero&amp;lt;1 || numero &amp;gt; 100){&lt;br /&gt;
            throw new LimitesException(&amp;quot;Fuera de los límites&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        sc.nextLine();  // Para que lee el salto de línea&lt;br /&gt;
        return (byte)numero;&lt;br /&gt;
    }&lt;br /&gt;
    public static String leerCadena() throws InputMismatchException,NoSuchElementException,Exception{ // Exception la usaremos en caso de que envíe la cadena vacía. No se recomienda utilizar el tipo de excepción &amp;#039;general&amp;#039;&lt;br /&gt;
        System.out.println(&amp;quot;Introduce una cadena:&amp;quot;);        // InputMismatchException,NoSuchElementException: Derivan de RunTimeException, por lo tanto son de tipo unchecked &lt;br /&gt;
        String cadena = sc.nextLine();&lt;br /&gt;
        &lt;br /&gt;
        if (cadena.length()==0){&lt;br /&gt;
            throw new Exception(&amp;quot;Longitud cadena igual a cero&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return cadena;&lt;br /&gt;
        &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static boolean leerBooleano() throws InputMismatchException,NoSuchElementException, IllegalStateException { // Derivan de RunTimeException, por lo tanto son de tipo unchecked&lt;br /&gt;
        System.out.println(&amp;quot;Introduce un booleano:&amp;quot;);&lt;br /&gt;
        &lt;br /&gt;
        boolean dato = sc.nextBoolean();&lt;br /&gt;
        return dato;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Clase Principal&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
::&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot; line enclose=&amp;quot;div&amp;quot; highlight=&amp;quot;&amp;quot; &amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * To change this license header, choose License Headers in Project Properties.&lt;br /&gt;
 * To change this template file, choose Tools | Templates&lt;br /&gt;
 * and open the template in the editor.&lt;br /&gt;
 */&lt;br /&gt;
package EjerciciosPOO.excepciones.ejercicio2;&lt;br /&gt;
&lt;br /&gt;
import java.util.InputMismatchException;&lt;br /&gt;
import java.util.NoSuchElementException;&lt;br /&gt;
import java.util.logging.Level;&lt;br /&gt;
import java.util.logging.Logger;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 *&lt;br /&gt;
 * @author clase&lt;br /&gt;
 */&lt;br /&gt;
public class Principal {&lt;br /&gt;
    &lt;br /&gt;
    public static void main(String[] arg){&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            byte numero = Lectura.leerEntero();&lt;br /&gt;
        } catch (LimitesException ex) {&lt;br /&gt;
            System.out.println(&amp;quot;Error en los límetes&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        catch (Exception e) {&lt;br /&gt;
            System.out.println(&amp;quot;Error general&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            String cadena = Lectura.leerCadena();&lt;br /&gt;
        } catch (InputMismatchException ex) {&lt;br /&gt;
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;
        } catch (NoSuchElementException ex) {&lt;br /&gt;
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;
        } catch (Exception ex) {&lt;br /&gt;
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        try {&lt;br /&gt;
            boolean valor = Lectura.leerBooleano();&lt;br /&gt;
        } catch (InputMismatchException ex) {&lt;br /&gt;
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;
        } catch (NoSuchElementException ex) {&lt;br /&gt;
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;
        } catch (IllegalStateException ex) {&lt;br /&gt;
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; -- [[Usuario:angelfg|Ángel D. Fernández González]] -- (2017).&lt;/div&gt;</summary>
		<author><name>Wiki</name></author>
		
	</entry>
</feed>