是否可以检索引起错误的命名空间? [英] Is it possible to retrieve the namespace of a raised error?

查看:135
本文介绍了是否可以检索引起错误的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从XQuery查询中引发错误时,例如:

When I raise an error from within an XQuery query, for instance with:

error( fn:QName( 'http://example.com', 'XMPL0001' ), 'Conflict' )

...以下是由BaseX返回(无论是与服务器通信还是在GUI中)

... the following is returned by BaseX (be it when communicating with the server, or from within the GUI)

Stopped at ., 1/7:  
[XMPL0001] Conflict

是否有可能检索错误的命名空间(在这种情况下 http://example.com )以及

Is it somehow possible to retrieve the namespace of the error (in this case http://example.com) as well?

我正在使用自定义的PHP客户端,我想使用此信息来防止与我的自定义错误代码的可能(未来)冲突,并解析错误以抛出标准的 BaseX\Exception 或自定义 SomeNamespace\Exception ,具体取决于错误的命名空间。

I'm using a customized PHP client and I would like to use this information to prevent possible (future) conflicts with my custom error codes and parse the errors to throw either a standard BaseX\Exception or a custom SomeNamespace\Exception, depending on the namespace of the error.

当然,我可以简单地使用另一个错误代码模式比典型的 ABCD1234 XQu红色图案,以防止可能的(未来)错误代码冲突,但可能使用命名空间对我更多,因为我可以定义一个统一的异常接口,如:

I could, of course, simply use another error code pattern than the typical ABCD1234 XQuery pattern, to prevent possible (future) error code conflicts, but the possible use of a namespace appeals to me more, because I can then define an uniform Exception interface, such as:

interface ExceptionInterface
{
    public function getCategory(); // the 4 alpha character part
    public function getCode();  // the 4 digit part
}






我目前正在使用BaseX 7.7.2。


I'm currently using BaseX 7.7.2, by the way.

推荐答案

是的,您可以使用错误命名空间中的一些变量,这些变量在范围内的try-catch语句,如下所示:

Yes, you can retrieve information about the error using a few variables in the error namespace, which are in scope of the try-catch statement, like so:

declare namespace err = "http://www.w3.org/2005/xqt-errors";

try {
    error( fn:QName( 'http://example.com', 'XMPL0001' ), 'Conflict' )
}
catch * {
    namespace-uri-from-QName($err:code)
}

这假定您使用的是XQuery 3.0。

This assumes that you are using XQuery 3.0.

这篇关于是否可以检索引起错误的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆