answersLogoWhite

0


Best Answer

Here is a code snippet illustrating exception handling:

try {

int a= 3 / 0 ;

} catch ( ArithmeticException e ) {

System.out.println ("An ArithmeticException has occured");

} finally {

// some code

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

In JAVA, is exception handling implicit or explicit or both. Explain with the help

of example java programs.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A program to explain the Exception Handling mechanisms in Java using the keywords try catch and finally?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How an exception subclass is created in java explain?

We can create a exception sub class by extending Exception class available in java


Explain about exception handling with multiple exception?

Exception handling in Java is done through a try-catch-finally block. The "try" block of code is where you put the code which may throw an exception. The "catch" block of code is where you put the code which will execute after an exception is thrown in the try block. This is often used to display an error message, or to mitigate problems caused by the exception. The "finally" block is where you put code that you want to execute after the try and catch blocks have been processed. // example code for catching exception while reading from a file try { // this line of code can throw a FileNotFoundException FileReader in = new FileReader("myfile.txt"); // this line of code can throw an IOException in.read(); } catch(FileNotFoundException ex) { // catch first exception type System.err.println("Cannot find myfile.txt!"); } catch(IOException ex) { //catch second exception type System.err.println("Cannot read from myfile.txt!"); } finally { // no matter what we want to close the file, so do it here // however, this line can also cause an exception, so we need to catch that, too try { in.close(); catch(IOException ex) { // not much we can do about an exception that occurs here } }


What is a classification of metadata and explain the features of each type of metadata?

Meta data, overall, can hold a huge amount of information about a website. However, the three most important types of meta data are: Meta keywords (the keywords that describe what a page is about) Meta Title (the page's title) Meta Description (a full, but short description of a webpage.)


What is an exception With an example program explain how it is handled?

An exception is literally that: an exception. Exceptions are thrown when something that shouldn't happen does. For example, if you're trying to turn "Hi" into an Integer, you'll get a NumberFormatException (in Java.) If there is nothing in place to handle an exception, the program will crash. Try-catch blocks are used for exception handling within methods, and exception throwing is used to give out exceptions, or let a different method handle it. Example program (Java): class ex{ public static void main(String[] args){ String Strx = "5a"; int x = 0; try{ x += Integer.parseInt(Strx); }catch(NumberFormatException e){ // If Strx is not an Integer x += Integer.parseInt("5"); } System.out.println("The value of x is " + x); // The value of x is 5 } } Alternatively, you could remove the try-catch blocks, and simply write "public static void main(String[] args) throws NumberFormatException" in the 2nd line of the program.


What is difference between exception and error in java and explain using a program?

Error occurs at runtime and cannot be recovered, Outofmemory is one such example. Exceptions on the other hand are due conditions which the application encounters, that can be recovered such as FileNotFound exception or IO exceptions

Related questions

Explain the mechanisms involved in disrupting body systems?

Explain the mechanisms involved in disrupting body systems?


Explain Error handling during file operations?

explain error handling during file operation?


What is the importance of customer handling?

Explain the importance of customer handling


How an exception subclass is created in java explain?

We can create a exception sub class by extending Exception class available in java


Explain how to support others to you?

Explain how to support others to understand the need for secure handling information


What are the main mechanisms used by secular scientists to explain evolution?

All educated and not ideologically blinded scientists explain evolution by three primary mechanisms. Genetic drift, gene flow and natural selection.I have the feeling you do not know what secular means.


What are ampoules with lyophilized?

PLEASE EXPLAIN HANDLING OF the lyophillzed gonadotrophin IN AMPOULES IS safe OR NOT


Why is important for moving and handling tasks to be carried out following specialist training?

explain why it is important for moving and handling tasks to be carried out following specialist training


Explain about exception handling with multiple exception?

Exception handling in Java is done through a try-catch-finally block. The "try" block of code is where you put the code which may throw an exception. The "catch" block of code is where you put the code which will execute after an exception is thrown in the try block. This is often used to display an error message, or to mitigate problems caused by the exception. The "finally" block is where you put code that you want to execute after the try and catch blocks have been processed. // example code for catching exception while reading from a file try { // this line of code can throw a FileNotFoundException FileReader in = new FileReader("myfile.txt"); // this line of code can throw an IOException in.read(); } catch(FileNotFoundException ex) { // catch first exception type System.err.println("Cannot find myfile.txt!"); } catch(IOException ex) { //catch second exception type System.err.println("Cannot read from myfile.txt!"); } finally { // no matter what we want to close the file, so do it here // however, this line can also cause an exception, so we need to catch that, too try { in.close(); catch(IOException ex) { // not much we can do about an exception that occurs here } }


Explain the importance of regulatory mechanisms in living things?

They keep environments relatively stable and maintained between certain limits.


What is a common payment to a attorney handling a lawsuit?

You need to consult with an attorney who can review your situation and explain your options.


Can anyone explain the different mechanisms that contribute to the regulation of breathing?

Mechanisms that contribute to the regulation of breathing is a sensor / control center that can recognize the change in pH of the cerebrospinal fluid. Which affects the nervous system and chemical signals which are when carbon dioxide rises in the blood?