import java.util.CFLib; public class MyException extends Exception { public static void main(String[] args) { ExceptionFactory factory = CFLib.getDefaultExceptionFactory(); try { throw factory.createException("My exception occurred!"); } catch (Exception exception) { System.out.println(exception.getMessage()); } } }
import java.util.CFLib; public class MyException extends Exception { public static void main(String[] args) { ExceptionFactory factory = CFLib.getDefaultExceptionFactory(); try { throw factory.createException("My exception occurred!", new IOException("IOException occurred!")); } catch (Exception exception) { System.out.println(exception.getMessage()); System.out.println(exception.getCause()); } } }This example is similar to the previous one, but it uses the overloaded createException() method that takes a message and a cause. The cause in this case is an instance of the IOException class.