All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.thisptr.jackson.jq.internal.tree.TryCatch Maven / Gradle / Ivy

There is a newer version: 198
Show newest version
package net.thisptr.jackson.jq.internal.tree;

import java.util.List;

import net.thisptr.jackson.jq.JsonQuery;
import net.thisptr.jackson.jq.Scope;
import net.thisptr.jackson.jq.exception.JsonQueryException;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;

public class TryCatch extends JsonQuery {
	private JsonQuery tryExpr;
	private JsonQuery catchExpr;

	public TryCatch(final JsonQuery tryExpr, final JsonQuery catchExpr) {
		this.tryExpr = tryExpr;
		this.catchExpr = catchExpr;
	}

	@Override
	public List apply(final Scope scope, final JsonNode in) throws JsonQueryException {
		try {
			return tryExpr.apply(scope, in);
		} catch (JsonQueryException e) {
			return catchExpr.apply(scope, new TextNode(e.getMessage()));
		}
	}

	@Override
	public String toString() {
		return String.format("(try (%s) catch (%s))", tryExpr, catchExpr);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy