Mockito.verify unreported exception java.lang.Throwable; must be caught or declared to be thrown

1,270 views
Skip to first unread message

nta1 nta1

unread,
Jun 16, 2019, 11:30:29 AM6/16/19
to mockito
Hi all, 

@Test
public void testMethod() throws Exception
{

try {
ContextClass ctx = new ContextClass();
Processor processor = Mockito.mock(processor.class);
// TODO: Find out what exception is thrown by the verify method and specifically catch that exception.

Mockito.verify(processor).process(ctx);
} catch(Exception ex) {
}

}

Above code throws the following error

[ERROR] unreported exception java.lang.Throwable; must be caught or declared to be thrown.

Any idea how could this issue be solved ?

Best,
Naveed

Fr Jeremy Krieg (Home)

unread,
Jun 17, 2019, 4:13:26 AM6/17/19
to moc...@googlegroups.com
Hi Naveed,

I pray that you are well.

I'm going to guess that if you replace "catch (Exception ex)" with "catch (Throwable t)" that will probably fix it.

If this doesn't fix it, then please post some some more information. In particular, can you clarify if this is a compile error, or a runtime error? You said "the code throws...", which suggests it was a runtime error - however, the error message is of a type that is usually associated with compile errors. It would also help if you could show exactly which line the error is occurring in. If you post this information (and anything else that you might have), then hopefully someone will be able to help you.

Blessings,
Fr Jeremy Krieg

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/7aad2e87-064a-4f7a-9ed9-f0bd5a8563b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages