[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

NotYetImplementedException

I am constructing some Java library.

I designed many methods to be required in future but could only implement part of them at now.

What is the best (or better) way to make library users notice that those functions will be supported but have not been implemented yet.(I don't like to erase all unimplemented methods from the sources.)

One idea is to make my own NetYetImplementedException as a child of RuntimeException. But it is strange for me that this kind of exception does not seem to be prepared in core library, or are there?

reference to other good sample, articles about exception designing are also welcome.
0
akky032499
Asked:
akky032499
  • 2
1 Solution
 
BugLighterCommented:
I think that you might want ot use the:    
java.lang.NoSuchMethodException .        

BugLighter.
0
 
atifmkCommented:
Hi,
     Best way to do this is to define your own Exception class with the proper error message and throw that exception in the not implemented methods.

   In JDK APIs also there are a lot of methods not implemented and they throw the RuntimeException. There are a lot of examples, but I am able to remeber just one at present and I am giving that here:

In java.sql.PreparedStatement, if you try to set the Date parameter like this:
_________________________________________________________
PreparedStatement stat = conn.prepareStatement("SELECT * FROM Test WHERE Date=?");
stat.setDate(1, new java.sql.Date(1999, 11, 29), new GregorianCalendar());
_________________________________________________________

throws a following RuntimeException:
_________________________________________________________
java.lang.UnsupportedOperationException at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setDate(JdbcOdbcPreparedState
ment.java:1541)
        at NotImplemented.<init>(NotImplemented.java:14)
        at NotImplemented.main(NotImplemented.java:27)
_________________________________________________________

Actually the Runtime exception is thrown in a no. of classes in JDK API, but there is not a single Exception class defined for that. Everywhere it's implementation dependent.

Hope this helps.

Regards,
Atif
0
 
BugLighterCommented:
Working with the NoSuchMethodException
or semiliar will prevent the Use of this method while developing because the
developer will have to compose a try catch block inorder to use the unsupported method, I preffer to use it this way inorder to protected the API users, but you can either use Atif sulotion.

Regards,
BugLighter.
0
 
akky032499Author Commented:
Thanks atifmk, Buglighter

I knew both suggested ways but now you let me know there are no other proper way.

I may use UnsupportedOperationException for my case instead of creating my own.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now