Hi Christian,

it works like a charme.

Thanks a lot.

Andreas

 

 

Von: Christian Grün <christian.gr...@gmail.com> 
Gesendet: Montag, 29. August 2022 13:58
An: Andreas Hengsbach | nexoma <andreas.hengsb...@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

 

Reply via email to