Skip to content

Type ex

Albert Farré Figueras edited this page Apr 9, 2019 · 2 revisions

Introduction

Type-ex it's a library to make easy application errors classification.

Motivation

In the old times all application errors were indexed in never-ending lists in big manuals to describe the possible problems and its solutions.

Quick start

  1. First of all include the Jar file in your compile and execution classpath. Maven
	<dependency>
		<groupId>org.bytemechanics</groupId>
		<artifactId>type-ex</artifactId>
		<version>X.X.X</version>
	</dependency>

Graddle

dependencies {
    compile 'org.bytemechanics:type-ex:X.X.X'
}
  1. Create your typified exceptions
package mypackage;
import org.bytemechanics.typeex.impl.TypifiedException;
public enum MyExceptionType implements ExceptionType<TypifiedException>{
	EXCEPTION_TYPE_NO_PARAMETERIZED("This message has no substitution parameters"),
	EXCEPTION_TYPE_PARAMETERIZED("This message has two {} substitution parameters {}"),
	;	
	private final String message;
	MyExceptionType(final String _message){
		this.message=_message;
	}	
	@Override
	public String getMessage() {
		return this.message;
	}
}
  1. Launch an exception Manually
throw MyExceptionType.EXCEPTION_TYPE_PARAMETERIZED
						.from(cause)
						.with("String1",1);

From lambda

Optional.of(null)
		.orElseThrow(MyExceptionType.EXCEPTION_TYPE_PARAMETERIZED
						.from(cause)
						.with("String1",1))
Clone this wiki locally