title: Invoke method that throws an exception in a different class
body: <p>I have the below code where I am lazy loading the instance creation of my class. </p>
  
  <pre><code>public class MyTest {
  private static MyTest test = null;
  private UniApp uniApp;  
  
  private MyTest(){
      try{                        
          uniApp = new UniApp("test","test123");          
      }
      catch(Exception e){
          e.printStackTrace();
          logger.error("Exception " +e+ "occured while creating instance of uniApp");
      }   
  }
  
  public static MyTest getInstance(){
      if (test == null){
          synchronized(MyTest.class){
              if (test == null){
                  test = new MyTest();
              }
          }
      }
      return test;
  }
  </code></pre>
  
  <p>In the constructor, I am creating an instance of UniApp that requires passing userid, password in its own constructor. If lets say I pass a wrong userid, password of the uniApp object, uniApp doesn't get created. Here is what I need -</p>
  
  <p>I am invoking the getInstance method in a different class - </p>
  
  <pre><code>    MyTest test=MyTest.getInstance();
  </code></pre>
  
  <p>And here, I want to add condition if failure of creation of uniApp happens, do blah. How do I do that?
  In general, if I am trying to invoke a method that throws an exception in class A in class B, and put a condition in B - if the method in class A throws exception, do this.</p>
  
  <p>How can I achieve this? Let me know if my question is confusing. I can edit it :)</p>