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

net.sf.saxon.s9api.SaxonApiException Maven / Gradle / Ivy

There is a newer version: 12.5
Show newest version
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018-2022 Saxonica Limited
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package net.sf.saxon.s9api;

import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.UncheckedXPathException;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.transpile.CSharpInjectMembers;
import net.sf.saxon.transpile.CSharpModifiers;

/**
 * An exception thrown by the Saxon s9api API. This is always a wrapper for some other underlying exception
 */
@CSharpInjectMembers(code="public override string Message {get => InnerException.Message;}")

public class SaxonApiException extends Exception {

    /**
     * Create a SaxonApiException
     *
     * @param cause the underlying cause of the exception
     */

    public SaxonApiException(Throwable cause) {
        super(cause);
    }

    /**
     * Create a SaxonApiException
     *
     * @param cause the underlying cause of the exception
     */

    public SaxonApiException(UncheckedXPathException cause) {
        super(cause.getXPathException());
    }

    /**
     * Create a SaxonApiException
     *
     * @param message the message
     */

    public SaxonApiException(String message) {
        super(new XPathException(message));
    }

    /**
     * Create a SaxonApiException
     *
     * @param message the message
     * @param cause   the underlying cause of the exception
     */

    public SaxonApiException(String message, Throwable cause) {
        super(new XPathException(message, cause));
    }

    /**
     * Returns the detail message string of this throwable.
     *
     * @return the detail message string of this Throwable instance
     *         (which may be null).
     */
    @Override
    @CSharpModifiers(code={"public", "override"})
    public String getMessage() {
        return getCause().getMessage();
    }

    /**
     * Get the error code associated with the exception, if there is one
     *
     * @return the associated error code, or null if no error code is available
     * @since 9.3
     */

    /*@Nullable*/
    public QName getErrorCode() {
        Throwable cause = getCause();
        if (cause instanceof XPathException) {
            StructuredQName code = ((XPathException) cause).getErrorCodeQName();
            return code == null ? null : new QName(code);
        } else {
            return null;
        }
    }

    /**
     * Get the line number associated with the exception, if known.
     * @return the line number (typically of a line in a stylesheet, query, or schema, but
     * in the case of validation errors it may be a line in a source document); or -1 if not known
     * @since 9.6
     */

    public int getLineNumber() {
        Throwable cause = getCause();
        if (cause instanceof XPathException) {
            Location loc = ((XPathException) cause).getLocator();
            return loc == null ? -1 : loc.getLineNumber();
        } else {
            return -1;
        }
    }

    /**
     * Get the URI of the module associated with the exception, if known.
     * @return the URI of the module (typically a stylesheet, query, or schema, but
     * in the case of validation errors it may be a source document); or null if not known
     * @since 9.6
     */

    public String getSystemId() {
        Throwable cause = getCause();
        if (cause instanceof XPathException) {
            Location loc = ((XPathException) cause).getLocator();
            return loc == null ? null : loc.getSystemId();
        } else {
            return null;
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy