com.cloudimpl:error-lib

java error code generation library

License

License

GroupId

GroupId

com.cloudimpl
ArtifactId

ArtifactId

error-lib
Last Version

Last Version

2.0.0.22
Release Date

Release Date

Type

Type

jar
Description

Description

java error code generation library
Source Code Management

Source Code Management

http://github.com/cloudimpl/errorcode4j/tree/master/error-lib

Download error-lib

How to add to project

<!-- https://jarcasting.com/artifacts/com.cloudimpl/error-lib/ -->
<dependency>
    <groupId>com.cloudimpl</groupId>
    <artifactId>error-lib</artifactId>
    <version>2.0.0.22</version>
</dependency>
// https://jarcasting.com/artifacts/com.cloudimpl/error-lib/
implementation 'com.cloudimpl:error-lib:2.0.0.22'
// https://jarcasting.com/artifacts/com.cloudimpl/error-lib/
implementation ("com.cloudimpl:error-lib:2.0.0.22")
'com.cloudimpl:error-lib:jar:2.0.0.22'
<dependency org="com.cloudimpl" name="error-lib" rev="2.0.0.22">
  <artifact name="error-lib" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.cloudimpl', module='error-lib', version='2.0.0.22')
)
libraryDependencies += "com.cloudimpl" % "error-lib" % "2.0.0.22"
[com.cloudimpl/error-lib "2.0.0.22"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

errorcode4j

error code generation library for java

usage :

.1) add error code generator plugin to your pom file

<plugin>
                <groupId>com.cloudimpl</groupId>
                <artifactId>errorcode-generator</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <id>xxx</id>
                        <goals>
                            <goal>ErrorCodeGenerator</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>

.2) then enable error code generation and define the erroFile name and packages using property tag

 <properties>
     <cloudImpl.errorCode.enable>true</cloudImpl.errorCode.enable>
     <cloudImpl.errorCode.package>com.cloudimpl.sample.error</cloudImpl.errorCode.package>
     <cloudImpl.errorCode.errorFileName>Sample</cloudImpl.errorCode.errorFileName>
 </properties>  

after define properties , build the maven project , it'll generate the ErrorCode file inside the defined package. in above example it is Sample.java inside the com.cloudimpl.sample.error package.

remove '_' enum and define your own enums for the errors.

sample errorCodes.

  USER_NOT_FOUND(0, "user [username] not found"),
  LOGIN_FAILED(1, "user login failed for user [username] and reason [reason]");

error source code will generate when you build the maven project inside the generated source code directory. example usage

public class Foo {

  public void func1() {
    throw SampleException.LOGIN_FAILED(err -> err.setUsername("john").setReason("invalid username or password"));
  }


  public void func2() throws CustomException {
    throw new CustomException("func2 exception");
  }

  // wrap original execption
  public void func3() {

    try {
      func2();
    } catch (CustomException ex) {
      throw SampleException.USER_NOT_FOUND(err -> err.setUsername("xxxx").wrap(ex));
    }
  }



  public static final class CustomException extends Exception {

    public CustomException(String message) {
      super(message);
    }


  }
 }

ErrorCode Options.

turn on/off stacktrace for peroformance reason. by default stack trace is ON

CloudImplException.STACK_FILL = false.

turn on/off tag fill on the error message . default is ON

CloudImplException.FILL_TAGS = false
com.cloudimpl

CloudImpl inc.

Versions

Version
2.0.0.22
2.0.0.20