Unchecked Exceptions


License

License

GroupId

GroupId

me.qoomon
ArtifactId

ArtifactId

unchecked-exceptions
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Unchecked Exceptions
Unchecked Exceptions
Project URL

Project URL

https://github.com/qoomon/unchecked-exceptions-java
Source Code Management

Source Code Management

https://github.com/qoomon/unchecked-exceptions-java.git

Download unchecked-exceptions

How to add to project

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

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.8.0

Project Modules

There are no modules declared in this project.

Unchecked Exception

License: MIT

Known Vulnerabilities

Maintainability

Test Coverage

Build Status

Maven Central

This lib hase zero dependencies and can be used to throw checked exceptions without declaring this in your method's head throws clause. And without wrapping Exception into a RuntimeException. Basically you can throw any Exception everywhere without catching them, happy throwing :-D

Methods

unchecked(Exception) rethrows any exception as unchecked exception, without wrapping exception.

  throw unchecked(checkedException);

unchecked(LambdaFunction) returns result or rethrows exception from lambda function as unchecked exception, without wrapping exception.

  return unchecked(() -> methodThrowingCheckedException())

Usage Examples

Try-Catch Block

Regular Code

  import static me.qoomon.UncheckedExceptions.*;

  public class Example {
      
      void example() {
          URL url;
          // code polition with try catch block
          try {
            url = new URL("https:/www.example.org");
          } catch (MalformedURLException e) {
            // ugly exception wrapping
            throw RuntimeException(e); 
          }
          System.out(url);
      }
  }

Unchecked Exception Code

  import static me.qoomon.UncheckedExceptions.*;

  public class Example {
      
      void example() {
        // get rid of code polition with try catch block
        // and ugly exception wrapping
        URL url = unchecked(() -> new URL("https:/www.example.org"));
        System.out(url);
      }
  }

Stream

Regular Code

  
    import static me.qoomon.UncheckedExceptions.*;
  
    public class Example {
        
        void example() {
          Stream.of("https:/www.example.org")
            .map(url -> {
              // code polition with try catch block
              try {
                return new URL(url);
              } catch (MalformedURLException e) {
                // ugly exception wrapping
                throw new RuntimeException(e);
              }
            });
        }
    }

Unchecked Exception Code

  
    import static me.qoomon.UncheckedExceptions.*;
  
    public class Example {
        
        void example() {
            Stream.of("https:/www.example.org")
                // get rid of code polition with try catch block
                // and ugly exception wrapping
                .map(url -> unchecked(() -> new URL(url)));
            }
    }

Versions

Version
1.0.0