Desculpa na maioria das exceptions que utilizo para testar tem uma classe de tratamento de erro como por exemplo NumberFormatException que tem getMessage()=, por isso nem testei e ja recomendei.
 
Quando utilizo somente Exception por tratrar diversos erros diferentes utilizo o .toString() tambem mas esqueci de especificar. Espero nao ter causado problemas ....abr
----- Original Message -----
Sent: Monday, March 31, 2003 12:23 PM
Subject: Re: [java-list] Exceção/Duvida

Marcio, isso não funciona, pq não há mensagem de erro criada. E ArrayIndexOutOfBoundsException é uma classe, não uma mensagem, e deve ser retornada pelo toString() ou pelo printStackTrace()
 
By API:
 
Class Throwable
 
getMessage
public String getMessage()
Returns the error message string of this throwable object.
Returns:
the error message string of this Throwable object if it was created with an error message string; or null if it was created with no error message
 
toString
public String toString()
Returns a short description of this throwable object. If this Throwable object was created with an error message string, then the result is the concatenation of three strings:
The name of the actual class of this object
": " (a colon and a space)
The result of the getMessage() method for this object
If this Throwable object was created with no error message string, then the name of the actual class of this object is returned.
Overrides:
toString in class Object
Returns:
a string representation of this Throwable.
 
 
André Barbosa
 
 
----- Original Message -----
From: "Marcio Ricardo Hatzlhoffer Correia" <[EMAIL PROTECTED]>
Sent: Monday, March 31, 2003 11:19 AM
Subject: Re: [java-list] Exceção/Duvida

> Utilize:
> int b[]=new int[10];
> try
>    {
>       System.out.print(b[23]);
>    }
> catch(ArrayIndexOutOfBoundsException e)
>    {
>       System.out.print(e.getMessage());
>    }
>
> ----- Original Message -----
> From: "Felipe Ferraz" <
[EMAIL PROTECTED]>
> To: <
[EMAIL PROTECTED]>
> Sent: Monday, March 31, 2003 10:36 AM
> Subject: [java-list] Exceção/Duvida
>
>
>   Tenho uma classe com o seguinte codigo:
>
> int b[]=new int[10];
> try
>    {
>       System.out.print(b[23]);
>    }
> catch(Exception e)
>    {
>       System.out.print(e.getMessage());
>    }
>  que se nao tiver o try me retorna a velha mensagem de
> arrayoutofbounds e etc, mas quando eu peço para que ele
> imprima o e.getmessage ele apenas imprime null, pergunto,
> como eu faço para que o programe nao aborte, lance a exceção
> mas a mensagem retornada seja a de arrayoutofbounds?
>
>
> ---
> UOL, o melhor da Internet
>
http://www.uol.com.br/
>
>
> ------------------------------ LISTA SOUJAVA ----------------------------
>
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP
> dúvidas mais comuns:
http://www.soujava.org.br/faq.htm
> regras da lista: http://www.soujava.org.br/regras.htm
> historico: http://www.mail-archive.com/java-list%40soujava.org.br
> para sair da lista: envie email para [EMAIL PROTECTED]
> -------------------------------------------------------------------------
>
>
>
> ------------------------------ LISTA SOUJAVA ----------------------------
>
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP
> dúvidas mais comuns:
http://www.soujava.org.br/faq.htm
> regras da lista: http://www.soujava.org.br/regras.htm
> historico: http://www.mail-archive.com/java-list%40soujava.org.br
> para sair da lista: envie email para [EMAIL PROTECTED]
> -------------------------------------------------------------------------

Responder a