Hi Christian,

it works like a charme.

Thanks a lot.

Andreas

 

 

Von: Christian GrĂ¼n <christian.gruen@gmail.com>
Gesendet: Montag, 29. August 2022 13:58
An: Andreas Hengsbach | nexoma <andreas.hengsbach@nexoma.de>
Cc: BaseX <basex-talk@mailman.uni-konstanz.de>
Betreff: Re: [basex-talk] Exception handling in XQuery-Java-Binding

 

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