首页 \ 问答 \ C ++项目具有精心设计的异常机制(C++ Project with well designed exception mechanism)

C ++项目具有精心设计的异常机制(C++ Project with well designed exception mechanism)

有没有人知道一个开源c ++应用程序与一个设计良好/强大的异常机制,所以我可以获得一些灵感? 我看到的大多数代码/示例都有可疑的事情:

  1. 使用消息字符串作为参数抛出对象。 似乎错了,因为它将异常标记为致命,可以向用户显示的错误消息更高,为客户端代码尝试处理异常留下了很小的空间。 即使异常是致命的,像diffirent语言环境(语言)之类的东西也会使得在抛出点处格式化消息对我来说似乎是一个坏主意。
  2. 使用从基本异常类派生的大量不同的异常类。 为每一个可能出错的东西(打开文件,读取文件,写入文件,创建线程等)引入一个新的类/类型感觉是错误的。 使用基类型捕获最高级别的所有未处理异常会丢失显示有意义错误消息所需的类型信息。
  3. 对每个组件/库使用从基本异常类派生的一个异常类,并为其指定错误代码作为参数以指示确切的错误。 使用基本类型捕获会导致模糊不清。 (我们捕获了谁的错误代码“3”?)...

一些正确方向的指针将受到欢迎。


Does anyone know a opensource c++ application with a well designed/robust exception mechanism so I can get some inspiration? Most code/examples I see do questionable things like:

  1. Throw objects with a message string as argument. Seems wrong because it marks the exception as fatal, a error message wich can be displayed to the user higher up leaves little room for client code trying to handle the exception. Even if the exception is fatal, things like diffirent locales (languages) makes formatting a message at the point of throw seem like a bad idea to me.
  2. Use tons of different exception classes derived from a base exception class. Just feels wrong introducing a new class/type for every single thing that can go wrong (open file, read file, write file, create thread, etc...). Catching all unhandled exceptions at the highest level using the base type loses type information required to display meaningfull error messages.
  3. Use one exception class derived from a base exception class for every component/library and give it a error code as argument to indicate the exact error. Catching with base type results in ambiguity. (Whose error code "3" did we catch? )...

Some pointers in the right direction would be welcome.


原文:https://stackoverflow.com/questions/10325330
更新时间:2023-05-30 19:05

最满意答案

我希望你能:

$array = [];
$faculty = array(2, 3, 4);
$message = array('test1', 'test2', 'test3');
$id = 1;
for ($key = 0; $key < count($faculty); $key++) {
    $array[$key]['faculty'] = $faculty[$key];
    $array[$key]['message'] = $message[$key];
    $array[$key]['id'] = $id;
}
print_r($array);

I hope this will you:

$array = [];
$faculty = array(2, 3, 4);
$message = array('test1', 'test2', 'test3');
$id = 1;
for ($key = 0; $key < count($faculty); $key++) {
    $array[$key]['faculty'] = $faculty[$key];
    $array[$key]['message'] = $message[$key];
    $array[$key]['id'] = $id;
}
print_r($array);

相关问答

更多
  • 列出monad 谁写了那么长的关于划定的问题的东西是坚果 - 在我花了3个小时试图搞清楚之后,我将在30秒内忘记它的一切! 更严重的是,与这个答案相比, shift / reset是如此令人难以置信的不切实际,这是一个笑话。 但是,如果我没有先分享这个答案,我们就不会有把内心彻底改变的快乐! 所以,请不要进行shift / reset除非他们对手头的任务至关重要 - 请原谅我,如果你觉得自己被学习的东西弄得很酷! 让我们不要忽视一个更直接的解决方案,List monad - 在这里用Array.protot ...
  • 只需使用: $output = array_merge($array1, $array2); 这应该解决。 因为如果一个键出现一次以上,所以使用字符串键(例如你的例子中的'44' ),一个键将覆盖同一个名称的过程。 因为在你的情况下,他们都有相同的价值,无论如何没有关系,它也将删除重复。 更新:我刚刚意识到,PHP将数字字符串键作为数字(整数),因此会像这样,这意味着它重新编号的键呢? 解决办法是重新创建密钥。 $output = array_combine($output, $output); 更新2 ...
  • 这不是你可以只使用php函数并调用它的情况 - 你必须自己做一些自定义逻辑。 这可行,但$array1是$array1和$array2在每个索引处都有相同的项目。 $array1; $array2; $mergedArray; for ($i=0; $i++; $i < count($array1) - 1) { //first add all the values from array1 $mergedArray[$i] = $array1[$i]; foreach($arra ...
  • 可能不是最干净的方法,但快速循环应该这样做。 我假设您已经验证并清理了表单数据,并确保数组大小相同。 $rows = array(); $num_results = count($_POST['link_name']); for($i = 0; $i < $num_results; $i++) { $rows[$i]['url'] = $_POST['link_url'][$i]; $rows[$i]['name'] = $_POST['link_name'][$i]; } Proba ...
  • 它应该像写作一样简单: array = [NSMutableArray array]; [array addObjectsFromArray:hArray]; [array addObjectsFromArray:iArray]; 为了更具体地说明您的示例,以下是编辑代码的方法: @property (strong, nonatomic) NSArray *hArray; @property (strong, nonatomic) NSMutableArray *array; @property (str ...
  • 试试: $array1 = array( /* your data */ ); $array2 = array( /* your data */ ); $output = array(); for ($i = 0; $i < count($array1); ++$i) { $output[] = $array1[$i] . ',' . $array2[$i]; } 要与fputcsv一起fputcsv : for ($i = 0; $i < count($array1); ++$i) { $ou ...
  • 好吧,我刚试过这个并且它有效: $new_array = array( $array_one, $array_two, ); 亲自尝试一下吧。 Well, I just tried this and it worked: $new_array = array( $array_one, $array_two, ); Try it yourself here.
  • 您可以从也存在于第二个array2数组中的元素中过滤例如第一个数组array1 。 var array1 = ["Vijendra","Singh"], array2 = ["Singh", "Shakya"], res = array1.filter(v => array2.indexOf(v) > -1); console.log(res); You could filter e.g. the first array array1 from the elemen ...
  • 我希望你能: $array = []; $faculty = array(2, 3, 4); $message = array('test1', 'test2', 'test3'); $id = 1; for ($key = 0; $key < count($faculty); $key++) { $array[$key]['faculty'] = $faculty[$key]; $array[$key]['message'] = $message[$key]; $array[$ke ...
  • [我的代码]虽然效率不高。 您只需要在两个阵列中的每个阵列上循环一次。 在您的示例函数中,嵌套循环内的代码将运行count($array_1) * count($array_2)次。 而在每个数组上循环一次只会count($array_1) + count($array_2)次。 (显然,当每个阵列中只有2个项目时,数字是相同的,但节省的费用很快就会增加。) 所以,在代码中,替代方案可能是这样的: $combined_array = array(); foreach(array($array_1, $arr ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。