c++ throw异常(学习)
#include <iostream>
#include <stdio.h>
using namespace std;
void my_copy(const char* src_file, const char* dest_file)
{
FILE *in_file, *out_file;
in_file = fopen(src_file, "rb");
if (in_file == NULL)
{
throw 1;
}
out_file = fopen(dest_file, "wb");
if (out_file == NULL)
{
throw 2;
}
char rec[1024];
size_t bytes_in, bytes_out;
while ((bytes_in = fread(rec, 1, 1024, in_file))>0)
{
bytes_out = fwrite(rec, 1, bytes_in, out_file);
if (bytes_in != bytes_out)
{
throw 3;
}
}
fflush(out_file);
fclose(out_file);
fclose(in_file);
}
int main()
{
try
{
my_copy("D:\\File\\1.txt", "D:\\File\\20190608\\1.txt");
}
catch (int e)
{
switch (e)
{
case 1:
printf("打开源文件出错\n");
break;
case 2:
printf("打开目标文件出错\n");
break;
case 3:
printf("拷贝文件出错\n");
break;
default:
printf("未知错误\n");
break;
}
}
system("pause");
return 0;
}
最新文章
- 屌丝giser成长记-大学篇
- linux下命令运行目录上程序前面要加./
- openssl API网络通信
- ubuntu13.04云主机部署gitlab6.6
- tty &; pty &; pts
- 【ASP.NET基础】简单企业产品展示网站--产品编辑CRUD
- mvc路由规则相关
- [精校版]The Swift Programming Language
- javascript数组总结(0504)
- bzoj2705
- Teacher YYF - POJ 3746(打表........)
- 第一个输出程序 Console.WriteLine
- 在调试安卓系统的时候需要这个 ”adb disable-verity“
- NTT中可用素数模数原根表
- 2883 -- 【TJOI2018】游园会
- CSS魔法堂:那个被我们忽略的outline
- 大端&;小端问题
- 17秋 软件工程 团队第五次作业 Alpha Scrum6
- Java自定义类加载和ClassPath类加载器
- 什么是Platform Services Controller