c++中的Exceptions异常处理(翁恺c++公开课[36])

让人想犯罪 __ 提交于 2020-02-13 01:47:52

Exceptions用于处理Run-time Error;

//文件读取的异常捕获伪代码
try{
    open the file;
    determine its size;
    allocate that much memory;
    read the file into memory;
    close the file;
}catch(fileOpenFailed){
    doSomething;
}catch(sizeDeterMinationFailed){
    doSomething;
}catch(memoryAllocationFailed){
    doSomething;
}catch(readFailed){
    doSomething;
}catch(fileCloseFailed){
    doSomething;   
}

 异常,让函数发现有自己无法处理的错误时抛出一个异常

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!