exception-factory
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.5%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Basic Info
- Host: GitHub
- Owner: Chrimle
- License: apache-2.0
- Language: Java
- Default Branch: main
- Homepage: https://chrimle.github.io/Exception-Factory/
- Size: 48.8 KB
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 4
Topics
Metadata Files
README.md
Exception Factory
Create Exception instances with Factory-methods and Builder patterns!
Import the Dependency
xml
<dependency>
<groupId>io.github.chrimle</groupId>
<artifactId>exception-factory</artifactId>
<version>0.4.0</version>
</dependency>
Example Usage
There are several ways of instantiating Exceptions using exception-factory. Here are some examples, given in the order of quick-and-easy to more customized Exceptions.
1. Using ExceptionFactory
Offers the creation of IllegalArgumentExceptions and IllegalStateExceptions, in the following ways:
```java import io.github.chrimle.exceptionfactory.ExceptionFactory; import io.github.chrimle.exceptionfactory.MessageTemplates;
import java.util.regex.Pattern;
import static io.github.chrimle.exceptionfactory.MessageTemplates.OneArgTemplate.*; import static io.github.chrimle.exceptionfactory.MessageTemplates.TwoArgTemplate.MUSTMATCHREGEX;
// Example of ExceptionFactory
static {
// Example of a One-Arg MessageTemplate, which throws "username MUST NOT be null".
if (username == null)
throw ExceptionFactory.illegalArgumentOf("username", MUSTNOTBE_NULL);
// Example of a Two-Arg MessageTemplate, which throws "username MUST match the RegEx ^[a-z]{3,15}$".
if (!Pattern.matches("^[a-z]{3,15}$", username))
throw ExceptionFactory.illegalArgumentOf("username", MUSTMATCHREGEX, "^[a-z]{3,15}$");
}
``
Refer to [MessageTemplates](src/main/java/io/github/chrimle/exceptionfactory/MessageTemplates.java) for all available *message templates*.
These are separated by how many *format specifiers* are needed, i.e.OneArgTemplaterequires ***one*** argument to format the resultingString`.
For custom messages, and/or providing a cause, see section below.
2. Using ExceptionBuilder
Offers the creation of any Exception-class, via a builder-pattern. This class is used by ExceptionFactory internally.
```java import io.github.chrimle.exceptionfactory.ExceptionBuilder; import io.github.chrimle.exceptionfactory.MessageTemplates;
import static io.github.chrimle.exceptionfactory.MessageTemplates.TwoArgTemplate.*;
// Example of ExceptionBuilder
static { if (1 + 1 == 3) { // Creating a plain Exception without message/cause. throw ExceptionBuilder.of(MakesNoSenseException.class).build(); }
try { oldUsername = userRepository.getUsername(userId); } catch (NoSuchUserException exception) { // Creating an exception with a custom message and cause. throw ExceptionBuilder.of(IllegalArgumentException.class) .setMessage("No user with userId '%s' exists!"::formatted, userId) .setCause(exception) .build(); } catch (ExceptionalException exception) { // Creating an exception with a custom format message string and cause. throw ExceptionBuilder.of(IllegalStateException.class) .setMessage("No clue what happened. Time to log everything %s, %s, %s, %s, %s", userId, newUsername, newLanguage, newDescription) .setCause(exception) .build(); }
// Creating an exception with a MessageTemplate. (Similar to ExceptionFactory) if (newUsername == oldUsername) throw ExceptionBuilder.of(IllegalArgumentException.class) .setMessage(MUSTNOTBEEQUALTO, "newUsername", oldUsername) .build(); } ```
JavaDocs
Please refer to the JavaDocs for further explanations.
Owner
- Name: Christopher Molin
- Login: Chrimle
- Kind: user
- Location: Gothenburg
- Company: Chrimle.com
- Website: https://chrimle.com
- Twitter: Chrimle
- Repositories: 1
- Profile: https://github.com/Chrimle
Software Engineer
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you want to reference this project, you could cite it as below." authors: - family-names: "Molin" given-names: "Christopher" orcid: "https://orcid.org/0009-0002-1005-3942" title: "Exception Factory" version: 0.4.0 date-released: 2025-08-03 url: "https://github.com/Chrimle/Exception-Factory"
GitHub Events
Total
- Release event: 3
- Watch event: 1
- Delete event: 10
- Issue comment event: 1
- Push event: 14
- Pull request event: 30
- Create event: 16
Last Year
- Release event: 3
- Watch event: 1
- Delete event: 10
- Issue comment event: 1
- Push event: 14
- Pull request event: 30
- Create event: 16
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Christopher Molin | 2****e | 4 |
| dependabot[bot] | 4****] | 1 |
Issues and Pull Requests
Last synced: 5 months ago
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 4
repo1.maven.org: io.github.chrimle:exception-factory
Create Exception instances with Factory-methods and Builder patterns!
- Homepage: https://chrimle.github.io/Exception-Factory
- Documentation: https://appdoc.app/artifact/io.github.chrimle/exception-factory/
- License: Apache License 2.0
-
Latest release: 0.4.0
published 5 months ago
Rankings
Dependencies
- actions/checkout v4 composite
- actions/setup-java v4 composite
- actions/checkout v4 composite
- actions/setup-java v4 composite
- actions/github-script v6 composite