NotInitializedException?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

NotInitializedException?

frank.schoenheit
Hi,

having to implement a service which has an explicit constructor taking
two arguments, which are necessary for operation of the component, I
wonder whether we already have some kind of NotInitializedException.

That is, technically it is possible to create the component without
actually invoking its constructor, so that is something I have to care
for in the implementation. I would like to do so by throwing a dedicated
exception, which clearly states the problem, whenever some (non-trivial)
method is invoked before fully constructing the object.

I imagine something like the following:

/** is thrown when a component is attempted to be used before it was
    completely constructed.
*/
exception NotInitializedException : public Exception
{
};

- Do we already have something like this (perhaps not with this name,
  but with this semantics)?

- Does it make sense to put this into css.lang? I'd say so, since
  - this is where XInitialization resides
  - we're talking about a basic "UNO language" feature here, namely
    constructors

- Should this go into udkapi or offapi? I'd say the former (again for
  consistency with XInitialization)

- Strictly speaking, the thingie should be named
  NotConstructedException: The fact that service constructors are
  implemented using XInitialization is a mere abus^W implementation
  detail (which hopefully will change sooner or later). So, it might
  make sense to not refer to "init" in the exception name.

Opinions?

Thanks & Ciao
Frank

--
- Frank Schönheit, Software Engineer         [hidden email] -
- Sun Microsystems                      http://www.sun.com/staroffice -
- OpenOffice.org Base                       http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NotInitializedException?

frank.schoenheit
now that I wrote this ...wrote:

> I imagine something like the following:
>
> /** is thrown when a component is attempted to be used before it was
>     completely constructed.
> */
> exception NotInitializedException : public Exception
> {
> };

it should better be a RuntimeException, shouldn't it?

Ciao
Frank

--
- Frank Schönheit, Software Engineer         [hidden email] -
- Sun Microsystems                      http://www.sun.com/staroffice -
- OpenOffice.org Base                       http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NotInitializedException?

stephan.bergmann
In reply to this post by frank.schoenheit
Frank Schönheit - Sun Microsystems Germany wrote:

> Hi,
>
> having to implement a service which has an explicit constructor taking
> two arguments, which are necessary for operation of the component, I
> wonder whether we already have some kind of NotInitializedException.
>
> That is, technically it is possible to create the component without
> actually invoking its constructor, so that is something I have to care
> for in the implementation. I would like to do so by throwing a dedicated
> exception, which clearly states the problem, whenever some (non-trivial)
> method is invoked before fully constructing the object.
>
> I imagine something like the following:
>
> /** is thrown when a component is attempted to be used before it was
>     completely constructed.
> */
> exception NotInitializedException : public Exception
> {
> };

As you already replied, I too think it should be a RuntimeException.

> - Do we already have something like this (perhaps not with this name,
>   but with this semantics)?
>
> - Does it make sense to put this into css.lang? I'd say so, since
>   - this is where XInitialization resides
>   - we're talking about a basic "UNO language" feature here, namely
>     constructors
>
> - Should this go into udkapi or offapi? I'd say the former (again for
>   consistency with XInitialization)

css.lang and ukdapi.

> - Strictly speaking, the thingie should be named
>   NotConstructedException: The fact that service constructors are
>   implemented using XInitialization is a mere abus^W implementation
>   detail (which hopefully will change sooner or later). So, it might
>   make sense to not refer to "init" in the exception name.

I would argue that it should be named NotInitializedException:  Properly
using a service constructor can never cause this exception.  It is using
the to-be-deprecated back door of createInstance/initialize that can
cause it.

Then again, not sure if a dedicated NotInitializedException is really
useful, or if a plain RuntimeException (with an appropriate message
string) would suffice.  What code would catch and handle
NotInitializedException (indicating a programming error)?

-Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NotInitializedException?

frank.schoenheit
Hi Stephan,

> I would argue that it should be named NotInitializedException:  Properly
> using a service constructor can never cause this exception.  It is using
> the to-be-deprecated back door of createInstance/initialize that can
> cause it.

Agreed.

> Then again, not sure if a dedicated NotInitializedException is really
> useful, or if a plain RuntimeException (with an appropriate message
> string) would suffice.  What code would catch and handle
> NotInitializedException (indicating a programming error)?

Because I like exceptions which state the problem in their name already.
Looking at today's code, too many developers are too lazy to care for
proper error messages (you find way too many "throw IOException()"s and
similar, if you want).
A dedicated exception type can help here. The approach of course doesn't
scale, but in some special cases such as here, I think the extra type is
justified.

Also, exception names can be examined programmatically, exceptions
messages can't.

Ciao
Frank

--
- Frank Schönheit, Software Engineer         [hidden email] -
- Sun Microsystems                      http://www.sun.com/staroffice -
- OpenOffice.org Base                       http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NotInitializedException?

frank.schoenheit
Hi Stephan,

>> Then again, not sure if a dedicated NotInitializedException is really
>> useful
> ...
> Because ...

Does your silence mean
[ ] I convinced you
[ ] you don't really care
[ ] I offended you by using some forbidden word like, uh, "lazy"
[ ] you did not find the time, yet, but still plan to blow away my
    arguments
[ ] other:
    _________________________

?

Ciao
Frank, just wondering whether he can go on / commit

--
- Frank Schönheit, Software Engineer         [hidden email] -
- Sun Microsystems                      http://www.sun.com/staroffice -
- OpenOffice.org Base                       http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NotInitializedException?

stephan.bergmann
In reply to this post by frank.schoenheit
Frank Schönheit - Sun Microsystems Germany wrote:

> Hi Stephan,
>
>>> Then again, not sure if a dedicated NotInitializedException is really
>>> useful
>> ...
>> Because ...
>
> Does your silence mean
> [ ] I convinced you
> [ ] you don't really care
> [ ] I offended you by using some forbidden word like, uh, "lazy"
> [ ] you did not find the time, yet, but still plan to blow away my
>     arguments
> [ ] other:
>     _________________________
>
> ?

[x] other: I don't care *that* much

> Ciao
> Frank, just wondering whether he can go on / commit

go on (if you still feel like it)  ;)

-Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]