Hi Andreas,

Exceptions in Java bindings are all caught by BaseX as we want to keep
control over unexpected behavior. For custom exceptions, the recommendable
approach is to throw instances of the QueryException class. This way, you
can directly access the error description:

// JAVA
import org.basex.query.*;

public class YourClass {
  public static void yourMethod() throws QueryException {
    throw new QueryException("Stopped...");
  }
}

(: XQUERY :)
try {
  Q{java:YourClass}yourMethod()
} catch basex:error {
  (: result: "Stopped..." :)
  $err:description
}

You can also define a custom error code as follows:

// JAVA
import org.basex.query.*;

... throw new QueryException(
  null, new QNm("custom"), "Stopped..."
);

(: XQUERY :)
try { ... } catch custom { ... }

Hope this helps,
Christian

Reply via email to