This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 60050 - Cannot compile test for method throwing exceptions
Summary: Cannot compile test for method throwing exceptions
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Marian Petras
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-15 14:15 UTC by zikmund
Modified: 2005-09-05 10:04 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zikmund 2005-06-15 14:15:54 UTC
Build 200506142000

1) Have a class with a method which throws an exception
2) Create test for this class
3) Compile Test class
4) ERROR:
Compilation fails with "unreported exceptions must be caught".

I think that code like:
   try {
      instance.CALL_METHOD(...);
   } catch (EXCEPTION_1) {
   } catch (EXCEPTION_2) {
   }
would be usefull.
Comment 1 Ondrej Rypacek 2005-06-15 14:22:15 UTC
The correct solution is to make the exceptions reported by the test method, and
thus pass them to the framework, which will report them as errors.

Comment 2 Marian Petras 2005-06-16 09:19:31 UTC
Accepted.

I will use the solution suggested by Ondrej Rypacek, i.e. I will just add the
throws-clause to the header of the test method. The throws-clause will simply
declare throwing of 'java.lang.Exception'.
Comment 3 Marian Petras 2005-06-20 12:04:15 UTC
Fixed in the trunk.

If the tested method declares to throw at least one exception other than
java.lang.RuntimeException or its subclass, the test method declares to throw
java.lang.Exception.

Modified file:
    junit/src/org/netbeans/modules/junit/TestCreator.java   (1.52)

Diff:
http://junit.netbeans.org/source/browse/junit/src/org/netbeans/modules/junit/TestCreator.java?r1=1.51&r2=1.52&diff_format=u
Comment 4 zikmund 2005-09-02 12:11:45 UTC
Verified in 20050902-0547.