[Solved] How to create exception from another class


throw new RuntimeException();

or

String exceptionMsg = "Error";
throw new RuntimeException(exceptionMsg);

public class X
{
   public X()
   {
      Y.CreateException();
      //or
      Y.CreateException("Error");
   }
}

public class Y
{
    public static void createException()
    {
         throw new RuntimeException();
    }

    public static void createException(String msg)
    {
         throw new RuntimeException(msg);
    }
}

1

solved How to create exception from another class