473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

implementing an interface method with an extra exception

i am implementing a custom version of the java.util.Map interface.
my custom version does some encryption stuff when making modifications to
the map via one of the 4 modification methods (put, putAll, remove, and
clear).
in doing this, i would like to also use one of my own exception objects...
so these 4 methods in the custom version should now also be defined with:
throws EncryptionException

because EncryptionException is not a subclass of RuntimeException.
this is a good thing, as i need it to be caught for proper error checking,
so making EncryptionException a subclass of RuntimeException is not an
acceptable solution.

the problem is, when i try to compile i get the error that my custom
methods cannot implement the defined versions in java.util.Map because the
defined versions don't specify that EncryptionException is thrown.

is it just me, or does this seem like a fairly large limitation in java?
is there an elegant way around this?

thanks,

murat

--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu

Jul 17 '05 #1
4 5035

"Murat Tasan" <ta***@eecs.cwru.edu> wrote in message
news:Pine.SOL.4.53.0401181802510.11057@homer...
i am implementing a custom version of the java.util.Map interface.
my custom version does some encryption stuff when making modifications to
the map via one of the 4 modification methods (put, putAll, remove, and
clear).
in doing this, i would like to also use one of my own exception objects...
so these 4 methods in the custom version should now also be defined with:
throws EncryptionException

because EncryptionException is not a subclass of RuntimeException.
this is a good thing, as i need it to be caught for proper error checking,
so making EncryptionException a subclass of RuntimeException is not an
acceptable solution.

the problem is, when i try to compile i get the error that my custom
methods cannot implement the defined versions in java.util.Map because the
defined versions don't specify that EncryptionException is thrown.

is it just me, or does this seem like a fairly large limitation in java?
is there an elegant way around this?

thanks,

murat

--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu


If you think about this carefully this is exactly how it should be. If Java
where to support adding exception types to the throws-list then code calling
the function through the base-class (or interface) is unaware of an
exception that might be thrown. This is accepted upon for RuntimeException
subclasses but only for those.

Remember that your implementation of Map could be passed to code that does
know anything else than a plain Map.

Silvio Bierman
Jul 17 '05 #2
thanks for the input. actually, a short while after posting i realized
that as well. i guess the problem comes back to the runtime exception
"controversy" that i've heard about but never experienced (until now).
i suppose i'll just make EncryptionException a subclass of
UnsupportedOperationException...

i'm not a fan of this, but it seems to be the only way.

thanks,

murat

On Mon, 19 Jan 2004, Silvio Bierman wrote:

"Murat Tasan" <ta***@eecs.cwru.edu> wrote in message
news:Pine.SOL.4.53.0401181802510.11057@homer...
i am implementing a custom version of the java.util.Map interface.
my custom version does some encryption stuff when making modifications to
the map via one of the 4 modification methods (put, putAll, remove, and
clear).
in doing this, i would like to also use one of my own exception objects...
so these 4 methods in the custom version should now also be defined with:
throws EncryptionException

because EncryptionException is not a subclass of RuntimeException.
this is a good thing, as i need it to be caught for proper error checking,
so making EncryptionException a subclass of RuntimeException is not an
acceptable solution.

the problem is, when i try to compile i get the error that my custom
methods cannot implement the defined versions in java.util.Map because the
defined versions don't specify that EncryptionException is thrown.

is it just me, or does this seem like a fairly large limitation in java?
is there an elegant way around this?

thanks,

murat

--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu


If you think about this carefully this is exactly how it should be. If Java
where to support adding exception types to the throws-list then code calling
the function through the base-class (or interface) is unaware of an
exception that might be thrown. This is accepted upon for RuntimeException
subclasses but only for those.

Remember that your implementation of Map could be passed to code that does
know anything else than a plain Map.

Silvio Bierman


--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu

Jul 17 '05 #3
You can always "nest" your exception in a RuntimeException.

throw new RuntimeException(new EncryptionException(...));

and get the "real" exception out by:

try {
....
....
}
catch(RuntimeException e) {
EncryptionException ee = (EncryptionException)e.getCause();
}

This example, of course, assumes that you know the RuntimeException actually
contains
the EncryptionException, but you get the idea.

-Bryan
"Murat Tasan" <ta***@eecs.cwru.edu> wrote in message
news:Pine.SOL.4.53.0401190200520.11261@homer...
thanks for the input. actually, a short while after posting i realized
that as well. i guess the problem comes back to the runtime exception
"controversy" that i've heard about but never experienced (until now).
i suppose i'll just make EncryptionException a subclass of
UnsupportedOperationException...

i'm not a fan of this, but it seems to be the only way.

thanks,

murat

On Mon, 19 Jan 2004, Silvio Bierman wrote:

"Murat Tasan" <ta***@eecs.cwru.edu> wrote in message
news:Pine.SOL.4.53.0401181802510.11057@homer...
i am implementing a custom version of the java.util.Map interface.
my custom version does some encryption stuff when making modifications to the map via one of the 4 modification methods (put, putAll, remove, and clear).
in doing this, i would like to also use one of my own exception objects... so these 4 methods in the custom version should now also be defined with: throws EncryptionException

because EncryptionException is not a subclass of RuntimeException.
this is a good thing, as i need it to be caught for proper error checking, so making EncryptionException a subclass of RuntimeException is not an
acceptable solution.

the problem is, when i try to compile i get the error that my custom
methods cannot implement the defined versions in java.util.Map because the defined versions don't specify that EncryptionException is thrown.

is it just me, or does this seem like a fairly large limitation in java? is there an elegant way around this?

thanks,

murat

--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu


If you think about this carefully this is exactly how it should be. If Java where to support adding exception types to the throws-list then code calling the function through the base-class (or interface) is unaware of an
exception that might be thrown. This is accepted upon for RuntimeException subclasses but only for those.

Remember that your implementation of Map could be passed to code that does know anything else than a plain Map.

Silvio Bierman


--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu

Jul 17 '05 #4

"Murat Tasan" <ta***@eecs.cwru.edu> wrote in message
news:Pine.SOL.4.53.0401190200520.11261@homer...
| thanks for the input. actually, a short while after posting i realized
| that as well. i guess the problem comes back to the runtime exception
| "controversy" that i've heard about but never experienced (until now).
| i suppose i'll just make EncryptionException a subclass of
| UnsupportedOperationException...
|
| i'm not a fan of this, but it seems to be the only way.
|
| thanks,
|
| murat
|
<snip>

Murat, why not write your class as a wrapper class, that way you can throw
any exceptions you like, you can still name the methods the same (e.g..add,
get etc) and call these methods on it's own internal Map with your extra
processing, or does your code rely on your class extending Map?
--
-P

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: idiot | last post by:
public DirectoryEntry Find(string, string) method get Exception from HRESULT: 0x80005008 public DirectoryEntry Find(string); method get NullReferenceException source code : string strSchema =...
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
8
by: hex | last post by:
Hi I make a class "MyClass" and this clas implements the Interface ICloneable. I want when I instance an object from MyClass and I call obj.Clone() it returns an object of MyClass type. for...
15
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } ...
1
by: Gomathi | last post by:
hi all, How to implement an interface in ASP.Net?. Consider my interface name is IExample. Then whatz mean by IExample ie = (IExample)obj1 Kindly let me know about this implementing interface...
2
by: Kevin Frey | last post by:
In a derived class I am trying to redefine the implementation of a interface method defined in a base class - the base class interface method was not declared virtual. I have yet to actually...
0
by: ddddd | last post by:
AM using the JDBC interface metho getProcedures() to get the stored procedures from the Database... Since this is common interface method am trying out with two different set of databases namely...
1
by: dba | last post by:
Hello All, And thanks in advance for taking the time to read this. I was given an interface definition to a COM object. Now I'd like to be able to compile the interface into it's own assembly...
2
by: Builder | last post by:
Hi, I imported following COM interface DECLARE_INTERFACE(IAxMediaCB) { STDMETHOD(BufferCB) ( LONGLONG theStartTime,
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.