"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Simple Exception Example

Simple Exception Example

Published on 2024-11-07
Browse:179
  • The example shows how to monitor and catch an exception.

  • Trying to access an index outside the bounds of an array generates an ArrayIndexOutOfBoundsException.

  • The program intentionally causes this exception and catches it.

Exemplo de exceção simples

  • The code to be monitored for exceptions is placed inside a try block.

  • When an exception occurs, it is thrown and caught by the catch block, ending the try block.

  • Control is not "called" to catch, but is transferred automatically.

  • If no exception occurs, the catch block is ignored and the program continues normally after the try block.

  • Exceptions raised by methods within the try block can also be caught by catch, if the method does not handle the exception on its own.

Exemplo de exceção simples

  • The exception generated by genException() is caught by the catch block in the main() method, as it was called within a try block.

  • If genException() had caught the exception, it would not have been passed to main().

Release Statement This article is reproduced at: https://dev.to/devsjavagirls/exemplo-de-excecao-simples-2ani?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3