问题描述
Java 和 C#,可能还有许多其他语言,都有一个预定义的异常类,当在不应该使用的地方使用空参数时会抛出该异常类.C ++中有类似的东西吗?如果没有,我可以使用其他预定义的异常还是应该定义自己的异常?
取消引用 NULL 指针是 C++ 中的未定义行为 - 这意味着代码看起来可以工作.不保证会抛出异常.您可以使用
std::invalid_argument>
异常(为其提供一个有意义的值 - p 为 NULL"),但您必须自己进行检查.
Both Java and C#, and probably many other languages too, have a predefined exception class that is thrown when a null parameter is used where it should not. Is there anything similar in C++? If not, is there another predefined exception I can use or should I define my own one?
Dereferencing a NULL pointer is undefined behaviour in C++ - which means the code can appear to work. An exception isn't guaranteed to be thrown. You can use the
std::invalid_argument
exception (provide a meaningful value to it - "p is NULL"), but you'll have to do the check yourself.
这篇关于是否有一个相当于 NullPointerException 的 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)