C ++(标准)异常和Unicode [英] C++ (Standard) Exceptions and Unicode

查看:127
本文介绍了C ++(标准)异常和Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,我正在处理unicode字符串,我想做一些错误报告标准例外。标准异常中包含的错误消息不是unicode。


通常这对我来说没有问题,因为我可以在非unicode中定义错误消息,并且有足够的信息,但在这种情况下,我想包含来自原始字符串的数据,这些可以是unicode。


如何处理异常中的unicode消息?你是否创建自己的自定义异常类,你是从标准异常派生出来的扩展到unicode,还是你有其他解决方案(例如规则不使用unicode在异常)?

I'm running into an issue where I'm processing unicode strings and I want to do some error reporting with standard exceptions. The error messages contained in standard exceptions are not unicode.

Usually that hasn't been a problem for me because I can define the error message in non-unicode and have enough information, but in this case I want to include data from the original strings, and these can be unicode.

How do you handle unicode messages in your exceptions? Do you create your own custom exception class, do you derive from the standard exceptions extending them to unicode, or do you have even other solutions to this problem (such as a rule "don't use unicode in exceptions")?

推荐答案

我认为Peter Dimov的理由在 Boost错误处理指南涵盖了这一点:

I think Peter Dimov's rationale as pointed out in the Boost error handling guidelines covers this well:


不要过于担心什么)
消息。很高兴有一个消息
,程序员认为
的机会,但是你不太可能
能够组成一个相关的和
用户可理解的错误消息在
点抛出异常。
当然,国际化是
超出了例外
类作者的范围。 Peter Dimov做了一个
的优秀论据,正确使用一个what()字符串的
作为一个
键到错误消息
formatters的表中。现在,如果只有我们可以得到
标准化的
标准的what()字符串标准
库抛出的异常...

Don't worry too much about the what() message. It's nice to have a message that a programmer stands a chance of figuring out, but you're very unlikely to be able to compose a relevant and user-comprehensible error message at the point an exception is thrown. Certainly, internationalization is beyond the scope of the exception class author. Peter Dimov makes an excellent argument that the proper use of a what() string is to serve as a key into a table of error message formatters. Now if only we could get standardized what() strings for exceptions thrown by the standard library...

这篇关于C ++(标准)异常和Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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