Java OCA OCP Practice Question 842

Question

Assume that a method named 'method 1' contains code which may raise a non-runtime (checked) Exception.

What is the correct way to declare that method so that it indicates that it expects the caller to handle that exception?

Select 2 options

  • A. public void m () throws Throwable
  • B. public void m () throw Exception
  • C. public void m () throw new Exception
  • D. public void m () throws Exception
  • E. public void m ()


Correct Options are  : A D

Note

For Option B.

Note that it should be 'throws' and not 'throw'

For Option C.

This is not the right syntax.

For Option E.

Non runtime exception must be declared in the throws clause.




PreviousNext

Related