-
Notifications
You must be signed in to change notification settings - Fork 0
Java Library Version
Yung Cet edited this page Jan 11, 2025
·
2 revisions
In addition to the Flutter package, the custom_error
library is also available as a Java library for use in Java-based applications.
Add the following Maven dependency to your build.gradle
:
dependencies {
implementation 'za.co.permanentlink:custom-error:1.0.1' // always use the 3 digit version number
}
Add the following Maven dependency to your pom.xml
:
// always use the 3 digit version number
<dependency>
<groupId>za.co.permanentlink</groupId>
<artifactId>custom-error</artifactId>
<version>1.0.1</version>
</dependency>
For more dependency options, visit Central Maven Repository.
package com.example;
import za.co.permanentlink.CustomError; // import package
public class Main {
public static void main(String[] args) {
// instantiate the object
CustomError error = new CustomError();
// add the error message
error.addError(-1, "Error Message");
// get the error code and message
// error.getErrorCode() = get error code
// error.getError() = get the error message
System.out.println(error.getErrorCode() + " " + error.getError());
// check if there is an error
if (error.hasAnError()){
System.out.println("An error occurred: "+ error.getErrorCode() + " " + error.getError());
}
// get the last error
System.out.println(error.getLatestError());
// Add multiple errors
error.addError(200, "Error 200");
error.addError(300, "Error 300");
// Retrieve all errors
var allErrors = error.getAllErrors();
System.out.println(allErrors);
}
}