-
Notifications
You must be signed in to change notification settings - Fork 0
How To: Create custom TypifiedCheckedExceptions
Albert Farré Figueras edited this page Dec 15, 2017
·
1 revision
In order to be able to create custom typified exceptions you only must inherit from org.bytemechanics.typeex.impl.TypifiedCheckedException and override the returning TypifiedCheckedException methods modifying it's return type with your class name:
- public TypifiedCheckedExceptions get();
- public TypifiedCheckedExceptions from(final Throwable cause);
- public TypifiedCheckedExceptions with(final Object... args);
It's important to override this methods in order to be able to build you custom exceptions maintaining the fluent syntax keeping your custom type (see #4 and #2 issues).
Also you should cast the result of the superclass to your new custom exception
Example:
import org.bytemechanics.typeex.impl.TypifiedCheckedException;
public class MyCheckedException extends TypifiedCheckedException {
public MyCheckedException(final ExceptionType _exceptionType,final Object... _arguments) {
super(_exceptionType, _arguments);
}
public MyCheckedException(final Throwable _cause,final ExceptionType _exceptionType,final Object... _arguments) {
super(_cause, _exceptionType, _arguments);
}
@Override
public MyCheckedException get() {
return (MyCheckedException)super.get();
}
@Override
public MyCheckedException from(final Throwable _cause) {
return (MyCheckedException)super.from(_cause);
}
@Override
public MyCheckedException with(final Object... _args) {
return (MyCheckedException)super.with(_args);
}
}