answersLogoWhite

0

Why handle exception?

Updated: 8/20/2019
User Avatar

Wiki User

12y ago

Best Answer

Because you can and you should, unless you want your program to crash if an exception occurs.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why handle exception?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is throw exception in java?

The presence of the keywords "throws exception" on a method signature means that, the method may throw an exception whhich it does not handle. It also means that the method that is calling or invoking it has to handle such exceptions. If the calling method does not handle that exception it would have to in turn use the same "throws exception" clause and throw it to its parent method.


Describe different ways that a function can handle errors?

There are two ways. The method can have a try catch block and handle the error/exception inside the method. Or The method can throw the exception under the assumption that the calling method would have the code to handle the exception that is thrown by this method


How do you handle multiple exception?

With multiple catch clauses, one for each exception that may be thrown.


Why you uses exception handling because you can handle exception using if Else statement?

We use exception handling so that the program can gracefully handle any situation that may be unexpected. We use try-catch for exception handling. if-else is a conditional logic checking mechanism


How exception subclass is created in java?

To handle the exceptions in large programs


What is the Event resulting from an unusual situation that disrupts normal program flow?

It is called an exception. There are two ways of handling exceptions inside java methods. The method can have a try catch block and handle the error/exception inside the method. Or The method can throw the exception under the assumption that the calling method would have the code to handle the exception that is thrown by this method


Throws exception function in java?

throws exception is a common signature pattern for methods. It is used to signify the fact that the code inside the method may throw exceptions of the types mentioned in the method signature. The calling method must have code to handle the exception effectively. Ex: public String getName() throws SQLException { ..... } This method's code can throw an SQLEXception and the calling method must have the code to handle this exception


How many catch blocks can you use with one try block with example?

A try block can have multiple catch blocks, each handling a different type of exception. Be careful about the order of laying the exceptions. Using Exception at the top will catch everything that is derived from it, thereby missing the other specfic exception catches. And there can also be only one finally block.


Why you handle exception in java?

Exception handling helps us catch or identify abnormal scenarios in our code and handle them appropriately instead of throwing up a random error on the front-end (User Interface) of the application. Exception handling allows developers to detect errors easily without writing special code to test return values. Even better, it lets us keep exception-handling code cleanly separated from the exception-generating code. It also lets us use the same exception-handling code to deal with a range of possible exceptions


Why use catch keyword in java?

no, because catch is used to handle exceptions which are generated from try block


If a method calls another method and that method throw an exception then caller method must be throw that exception or not?

If method A calls method B and method B throws an exception, then method A must handle that exception. It does not have to throw the exception if it is in a try-catch block, but it must do something to deal with it.Note that this only applies to checked exceptions. If method B throws an unchecked exception, then A is allowed to ignore it.


Is error and exception same?

Error: Any departure from the expected behavior of the system or program, which stops the working of the system is an error. Exception:Any error or problem which one can handle and continue to work normally. Note that in Java a compile time error is normally called an "error," while a runtime error is called an "exception." Errors don't have subclasses while exception has two subclasses, they are compile time exception or checked exception (ClassNotFound Exception, IOException, SQLException etc.) and runtime or unchecked exception(ArrayIndexOutOfBounds Exception, NumberFormat Exception).