You can instantiate your singleton instance in a static method:

class C{

    private static C mInstance = null;

    public static C getInstance() throws YourException {
           if (mInstance == null )  {
                 mInstance = new C(); //it throws YourException
            }

           return mInstance;
    }

}

On Fri, May 4, 2012 at 10:40 AM, Daniel Drozdzewski <
[email protected]> wrote:

> On 4 May 2012 01:24, [email protected] <[email protected]> wrote:
> > public class TheClass extends Guigui
> > {
> > ...
> > /*#! Singleton */
> >        static
> >        {
> >                if (m_instance == null) {
> >                        try {
> >                                m_instance = new TheClass();
> >                        }
> >                        catch (Throwable e) {
> >                                throw new
> RuntimeException(e.getMessage());
> >                        }
> >                }
> >        }
> > ...
> > }
>
>
> What if the constructor could throw a genuine exception (say file not
> found) or you wanted to supply some non-static arguments to it?
>
> --
> Daniel Drozdzewski
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Adriano Godinho

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to