{"id":20881966,"url":"https://github.com/firaja/capture4j","last_synced_at":"2026-04-17T03:31:37.628Z","repository":{"id":138120048,"uuid":"227584007","full_name":"firaja/capture4j","owner":"firaja","description":"This library aims to remove from your code bulky try-catch blocks and make your code easier to read and maintain.","archived":false,"fork":false,"pushed_at":"2020-10-20T10:02:06.000Z","size":72,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-31T21:13:49.016Z","etag":null,"topics":["bettercode","clean-code","exceptions","java-library","maintainability"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firaja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-12T10:49:30.000Z","updated_at":"2020-10-20T10:02:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"5c6b5a2b-ac56-4448-9473-fceb936a5267","html_url":"https://github.com/firaja/capture4j","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/firaja/capture4j","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firaja%2Fcapture4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firaja%2Fcapture4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firaja%2Fcapture4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firaja%2Fcapture4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firaja","download_url":"https://codeload.github.com/firaja/capture4j/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firaja%2Fcapture4j/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31913581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bettercode","clean-code","exceptions","java-library","maintainability"],"created_at":"2024-11-18T07:28:27.898Z","updated_at":"2026-04-17T03:31:37.605Z","avatar_url":"https://github.com/firaja.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Capture4J\n\n[![Build Status](https://travis-ci.org/firaja/capture4j.svg?branch=master)](https://travis-ci.org/firaja/capture4j)\n[![Maintainability](https://api.codeclimate.com/v1/badges/6eeea4a9b5c9207ffbea/maintainability)](https://codeclimate.com/github/firaja/capture4j/maintainability)\n[![codecov](https://codecov.io/gh/firaja/capture4j/branch/master/graph/badge.svg)](https://codecov.io/gh/firaja/capture4j)\n![License](https://img.shields.io/github/license/firaja/capture4j)\n\nThis library aims to remove from your code bulky try-catch/if-else blocks and make your code easier to read and maintain.\n\nWrite less repetitive checks and enjoy coding efficiently.\n\n## Getting Started\nThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.\n\n### Prerequisites\nMake sure you have installed all of the following prerequisites on your development machine:\n * **Java JDK 1.8+** - You can use a JDK from any vendor, but it is recommended to use \n [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html) or \n [OpenJDK](https://openjdk.java.net/install/)\n * **Maven 3+** - [Download and install](https://maven.apache.org/install.html)\n \n### Installing\n\n#### Git\n```shell script\ngit clone git@github.com:firaja/capture4j.git\ncd capture4j\nmvn clean install\n```\n\n#### Maven (requires GitHub Authentication)\nInsert the following dependency in your `pom.xml`\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003edev.firaja.utils\u003c/groupId\u003e\n  \u003cartifactId\u003ecapture4j\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\nThen run\n```shell script\nmvn install\n```\n\n## Profit\n\nHere a classic example where a method returns the same value in case of *error*\n```java\npublic int doSomething(MyObject myObject)\n    {\n        if(myObject == null || myObject.getId() == null)\n        {\n            return -1;\n        }\n\n        String name;\n        try\n        {\n            name = readNameFromSomewhere(myObject.getId());\n        } \n        catch (EntryNotFoundException e)\n        {\n            return -1;\n        }\n\n        if(name != null \u0026\u0026 name.indexOf(45) == 'a')\n        {\n            return -1;\n        }\n\n        return 1;\n    }\n```\nwhile the same method can be rewritten with **capture4j** like this\n```java\n@EasyCapture(returns = \"-1\")\n    public int doSomething(MyObject myObject)\n    {\n        String name = readNameFromMyDB(myObject.getId());\n        return name.indexOf(45) == 'a' ? 1 : -1;\n    }\n```\n\nYou can specify the type of exception you want to treat\n```java\n@EasyCapture(what = IllegalStateException.class, returns = \"illegal\")\n@EasyCapture(what = NullPointerException.class, returns = \"null pointer :(\")\npublic String doSomething()\n{\n    ...\n}\n```\n\nOr even use a custom handler for standard or custom exceptions\n```java\n@Capture(what = MyException.class, with = MyHandler.class)\npublic long doSomething()\n{\n    ...\n}\n```\n```java\nclass MyHandler implements Handler\u003cLong\u003e\n{\n    public Long handle(Throwable theException) // \u003c- MyException\n    {\n        long fallback = doSomeCalculation();\n        logger.warn(\"Something went wrong :( but I'returning {}.\", fallback, theException);\n        return fallback;\n    }    \n}\n```\n## Versioning\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/firaja/capture4j) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/firaja/capture4j?include_prereleases)\n\nWe use [SemVer](http://semver.org/) for versioning. \n\nFor the versions available, see the [tags on this repository](https://github.com/firaja/capture4j/tags).\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Authors\n\n* **David Bertoldi** - *Initial work* - [firaja](https://github.com/firaja)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiraja%2Fcapture4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiraja%2Fcapture4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiraja%2Fcapture4j/lists"}