rhiannonlm3118 rhiannonlm3118
  • 14-07-2019
  • Computers and Technology
contestada

What is the difference between the throw statement and the throws clause?

Respuesta :

Branta Branta
  • 21-07-2019

Answer:

throw and throws represent different constructs in Java programming language.

Explanation:

throw is used to explicitly throw an Exception from within a code segment.

For example:

public void throw_test(String str){

        if(str==null) throw new NullPointerException();

}

throws is used to specify an exception list which may be thrown by a method:

For example:

public String readFromFile(File f) throws IOException {

.....

// Some code fragment which could throw a IOException

}

Answer Link

Otras preguntas

How should Audrey’s response be punctuated to show that she is stunned?
(PLS HELP!) Write a 250 word essay explaining Arizona's history
Which simplified ratio correctly compares 12 yards to 20 feet?
Deferring to another court’s decision on a prior matter in order to decide on a new controversy is known as:
음 12 18+ 12 70 pls answer
What is the slope of the line?
A line passes through the point (-1, 3) and has a slope of -5. Write an equation in slope-intercept form for this line. L X 5 ?
fill in the blanks to explain another memory grandpa shares with amara.
Analyze the changing view of depletion of a forest to create wood products in context of GDP.
Marijuana is an accepted medical treatment for the nausea and vomiting associated with chemotherapies. a. True b. False