获取函数和类的错误信息的正确方法 [英] Proper way to get error information for functions and class

查看:72
本文介绍了获取函数和类的错误信息的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从函数/类或应用程序接收错误信息并组织信息的最佳方法是什么?



我通常会返回/生成公共整数错误值具有包含异常信息的字符串错误值为public。

所有子函数调用都会将整数值返回到父函数,并且这一直持续到main函数获取错误值为止。 />


任何建议,文章,书籍,讨论如何做到这一点?



谢谢

What is the best method for receiving error information from a function/class or application and organizing the information?

I usually return/make public integer error values and have string error values which contain the exception information as public.
All the child function calls keep returning the integer value to the parent functions and this keeps on going until the main function get the error value.

Any advice, articles, books, discussions on how to do this?

Thanks

推荐答案

忘记错误信息和错误,包含结构化异常处理。忘记收集和组织这样的信息,忘记一般的防御性编程,忘记处理每一个例外情况,放手。这一切都已经成为历史。



很难用一个简单的答案来解释这个概念。结构化异常处理是最伟大的发明;我认为它比整个OOP更重要。请参阅:

http://en.wikipedia.org/wiki/Structured_exception_handling [< a href =http://en.wikipedia.org/wiki/Structured_exception_handlingtarget =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com/en-us/library/windows /desktop/ms680657%28v=vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ms173160.aspx [ ^ ]。



我提供了一个简短的解释在我过去回答的事情的本质: C#构造函数中的异常导致调用者分配失败吗? [ ^ ]。



异常处理机制是时间机器。



-SA
Forget "error information" and "errors", embrace Structured Exception Handling. Forget collecting and organizing of such information, forget defensive programming in general, forget handling each and every exception case, let go. That all have gone to history.

It''s hard to explain the concept in a one quick answer. Structured exception handling is the greatest invention; I value it more than whole OOP. Please see:
http://en.wikipedia.org/wiki/Structured_exception_handling[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms680657%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms173160.aspx[^].

I provided a short explanation of the essence of things in my past answer: Does Exception in C# Constructor Cause Caller Assignment to Fail?[^].

Exception handling mechanism is a time machine.

—SA


这篇关于获取函数和类的错误信息的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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