Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src/main Manifold project-wide changes: Aug 12, 2019
README.md bump version Aug 20, 2019
pom.xml bump version Aug 20, 2019

README.md

Manifold : Exceptions

Simply add the manifold-exceptions dependency to your project. Now checked exceptions behave like unchecked exceptions! No more compiler errors, no more unintentional exception swallowing, no more boilerplate try/catch/wrap/rethrow nonsense. This is how most modern JVM languages behave, now you have the option to make Java do the same.

Table of Contents

No More Catch-n-Wrap

The vast majority of checked exceptions go unhandled, instead they are caught, wrapped in unchecked exceptions, and rethrown like this:

URL url;
try {
  url = new URL("http://manifold.systems");
}
catch(MalformedURLException e) {
  throw new RuntimeException(e);
}
process(url);

This code alone explains why the designers of modern languages such as Scala, Kotlin, and others chose not to follow Java's example. The exceptions plugin option provides you with the same choice. With it enabled you can write the same code like this:

process(new URL("http://manifold.systems"));

Sells itself.

Lambdas

Perhaps the most offensive checked exception use-cases involve lambdas:

List<String> strings = ...;
List<URL> urls = list
  .map(URL::new) // Unhandled exception error: MalformedURLException
  .collect(Collectors.toList());

The checked exception prevents concise lambda usage here. With Manifold, however, you are free to write code as you like:

List<String> strings = ...;
List<URL> urls = list
  .map(URL::new) // Mmm, life is good
  .collect(Collectors.toList());

IDE Support

Manifold is best experienced using IntelliJ IDEA.

Install

Get the Manifold plugin for IntelliJ IDEA directly from IntelliJ via:

SettingsPluginsMarketplace ➜ search: Manifold

echo method

Sample Project

Experiment with the Manifold Sample Project via:

FileNewProject from Version ControlGit

echo method

Enter: https://github.com/manifold-systems/manifold-sample-project.git

echo method

Use the plugin to really boost your productivity. With the plugin installed IntelliJ is aware of all things Manifold, including checked exception handling e.g., the editor won't complain about checked exceptions.

Building

Building this project

The manifold-exceptions project is defined with Maven. To build it install Maven and run the following command.

mvn compile

Using this project

The manifold-exceptions dependency works with all build tooling, including Maven and Gradle. It also works with Java versions 8 - 12.

Here are some sample build configurations references.

Note you can replace the manifold-exceptions dependency with manifold-all as a quick way to gain access to all of Manifold's features.

Gradle

Java 8

Here is a sample build.gradle file using manifold-exceptions with Java 8:

plugins {
    id 'java'
}

group 'com.example'
version '1.0-SNAPSHOT'

targetCompatibility = 1.8
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'systems.manifold', name: 'manifold-exceptions', version: '2019.1.12'
}

tasks.withType(JavaCompile) {
    options.compilerArgs += '-Xplugin:Manifold'
    options.fork = true
}

Use with accompanying settings.gradle file:

rootProject.name = 'MyStringTemplatesProject'

Java 11+

Here is a sample build.gradle file using manifold-exceptions with Java 11:

plugins {
    id 'java'
}

group 'com.example'
version '1.0-SNAPSHOT'

targetCompatibility = 11
sourceCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'systems.manifold', name: 'manifold-exceptions', version: '2019.1.12'

    // Add manifold-exceptions to -processorpath for javac
    annotationProcessor group: 'systems.manifold', name: 'manifold-exceptions', version: '2019.1.12'
}

tasks.withType(JavaCompile) {
    options.compilerArgs += '-Xplugin:Manifold'
    options.fork = true
}

Use with accompanying settings.gradle file:

rootProject.name = 'MyExceptionsProject'

Maven

Java 8

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>my-exceptions-app</artifactId>
    <version>0.1-SNAPSHOT</version>

    <name>My Exceptions App</name>

    <properties>
        <!-- set latest manifold version here --> 
        <manifold.version>2019.1.12</manifold.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>systems.manifold</groupId>
            <artifactId>manifold-exceptions</artifactId>
            <version>${manifold.version}</version>
        </dependency>
    </dependencies>

    <!--Add the -Xplugin:Manifold argument for the javac compiler-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <!-- Configure manifold plugin-->
                        <arg>-Xplugin:Manifold</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Java 11+

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>my-exceptions-app</artifactId>
    <version>0.1-SNAPSHOT</version>

    <name>My Exceptions App</name>

    <properties>
        <!-- set latest manifold version here --> 
        <manifold.version>2019.1.12</manifold.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>systems.manifold</groupId>
            <artifactId>manifold-exceptions</artifactId>
            <version>${manifold.version}</version>
        </dependency>
    </dependencies>

    <!--Add the -Xplugin:Manifold argument for the javac compiler-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <!-- Configure manifold plugin-->
                        <arg>-Xplugin:Manifold</arg>
                    </compilerArgs>
                    <!-- Add the processor path for the plugin (required for Java 9+) -->
                    <annotationProcessorPaths>
                        <path>
                            <groupId>systems.manifold</groupId>
                            <artifactId>manifold-exceptions</artifactId>
                            <version>${manifold.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

License

Open Source

Open source Manifold is free and licensed under the Apache 2.0 license.

Commercial

Commercial licenses for this work are available. These replace the above ASL 2.0 and offer limited warranties, support, maintenance, and commercial server integrations.

For more information, please visit: http://manifold.systems//licenses

Contact: admin@manifold.systems

Versioning

For the versions available, see the tags on this repository.

Author

You can’t perform that action at this time.