|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
A program can use exceptions to indicate that an error occurred. To throw an exception, use thethrowstatement and provide it with an exception object — a descendant ofThrowable— to provide information about the specific error that occurred. A method that throws an uncaught, checked exception must include athrowsclause in its declaration.A program can catch exceptions by using a combination of the
try,catch, andfinallyblocks.The
- The
tryblock identifies a block of code in which an exception can occur.- The
catchblock identifies a block of code, known as an exception handler, that can handle a particular type of exception.- The
finallyblock identifies a block of code that is guaranteed to execute, and is the right place to close files, recover resources, and otherwise clean up after the code enclosed in thetryblock.trystatement should contain at least onecatchblock or afinallyblock and may have multiplecatchblocks.The class of the exception object indicates the type of exception thrown. The exception object can contain further information about the error, including an error message. With exception chaining, an exception can point to the exception that caused it, which can in turn point to the exception that caused it, and so on.