answersLogoWhite

0

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

12y ago

What else can I help you with?

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 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


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.)

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 is proximate mechanisms?

Proximate mechanisms refer to biological processes that explain how a particular behavior or trait occurs in an organism, focusing on the immediate causes such as hormones, brain activity, or environmental stimuli. These mechanisms are concerned with the immediate mechanisms that underlie behavior, as opposed to ultimate mechanisms which consider the evolutionary reasons behind the behavior.


What are ampoules with lyophilized?

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


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 } }


Can you explain how the keyword structure to name converter works?

The keyword structure to name converter works by taking a set of keywords and arranging them in a way that forms a coherent and meaningful name. It analyzes the keywords and organizes them in a specific order to create a name that accurately represents the content or concept associated with those keywords.


Can you explain how the keyword generator panel works and how it can help in generating relevant keywords for SEO optimization?

The keyword generator panel is a tool that suggests relevant keywords based on a topic or website. It helps in generating keywords for SEO by providing a list of terms that people are searching for online. These keywords can be used in website content to improve search engine rankings and attract more visitors.


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


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.