answersLogoWhite

0

What is unchecked exception?

Updated: 8/9/2023
User Avatar

Wiki User

10y ago

Best Answer

A checked exception is an exception which the Java source code must deal with, either by catching it or declaring it to be thrown. Unchecked exceptions are all exceptions which do not follow this rule.

When an unchecked exception is thrown, it is usually caused by a misuse of code - passing a null or otherwise incorrect argument. This includes classes like NullPointerException and IllegalArgumentException.

Checked exceptions are generally caused by faults outside of the code itself - missing resources, networking errors, and problems with threads come to mind. These could include subclasses of FileNotFoundException, UnknownHostException, etc.

The Java documentation (link below) gives some loose guidelines to follow when trying to decide which type of exception to use: "If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception."

From a purely code-oriented point of view, a checked exception is a subclass of Exception, while an unchecked exception is a subclass of RuntimeException.

User Avatar

Wiki User

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

Wiki User

10y ago

An exception for which it is not required to provide a local try statement, or to propagate via a throws clause defined in the method header. An exception that is not handled will cause program termination if it is thrown

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

The exception which are not checked by the java compiler is called unchecked exceptions.. for example null pointer exception, array out of bound exception..etc

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is unchecked exception?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Does throws throws only unchecked exception?

You can throw any type of exception you want, including an unchecked exception.


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


Checked and unchecked exceptions?

Unchecked exceptions : * represent defects in the program (bugs) - often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes : "Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time." * are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException * a method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so) Checked exceptions : * represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files) * are subclasses of Exception * a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow) It is somewhat confusing, but note as well that RuntimeException (unchecked) is itself a subclass of Exception (checked).


How many constructors does class Exception have?

The Exception class has 4 constructors. They are: a. Exception() b. Exception(String arg) c. Exception(String arg, Throwable arg1) d. Exception(Throwable arg)

Related questions

Does throws throws only unchecked exception?

You can throw any type of exception you want, including an unchecked exception.


What are the types of exception in java?

Exceptions are of two types: checked exceptions and unchecked exceptions.


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


Difference between checked and unchecked exception?

Checked exceptions are exceptions which need to be handled explicitly. These are the ones which require a try-catchblock or a throws keyword.Unchecked exceptions are exceptions which have no obligation to be handled. A NullPointerException is one common example.


Checked and unchecked exceptions?

Unchecked exceptions : * represent defects in the program (bugs) - often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes : "Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time." * are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException * a method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so) Checked exceptions : * represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files) * are subclasses of Exception * a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow) It is somewhat confusing, but note as well that RuntimeException (unchecked) is itself a subclass of Exception (checked).


What is the use of throw statement?

throws keyword/statement is basically used to handle exception in java. throws keyword is used to handle "unchecked exceptions". Example: public void enterdata()throws IOException { BufferedReader inp=new BufferedReader(new InputStreamReader(System.in)); int i=Integer.parseInt(inp.readLine()); } Now after the enterdata function we have used throws keyword because the"readLine" method throws an unchecked exception ie., IOException during user input which cannot be handled by try catch block.


What cells undergo unchecked rapid division in the body?

Cancer cells undergo unchecked rapid division in the body.


How you know that the unchecked items were left by another culture?

how you know that the unchecked native American mound builders items were left by another culture


How do you use unchecked in a sentence?

well you could say "i have and unchecked mailbox in Alabama" use as a something that hasn't been updated like a mail box.


What branch of government has the most unchecked power?

homeland security


What would happen if despotism were allowed to reign unchecked?

there will be tyranny