/********************************************\
|    欢迎转载, 但请保留作者姓名和原文链接, 祝您进步并共勉!     |
\********************************************/
								
								
						
						
						
				
				
						C++异常处理一例
						
								作者: Jerry Cat
时间: 2006/05/30
链接: http://www.cppblog.com/jerysun0818/archive/2006/05/30/7851.html
						
						
						
						
				
				
						
#include<fstream.h>
#include<iostream.h>
#include<stdlib.h>
		
		
				void main()
{
    ifstream source("c:\abc.txt");  //打开文件
    char line[128];
		
		
				    try //定义异常
    {
        if (source.fail())
        throw "txt";  //抛掷异常
    }
    catch(char * s)   //定义异常处理
    {
        cout<<"error opening the file "<<s<<endl;
        exit(1);
    }
		
		
				    while(!source.eof())
    {
        source.getline(line, sizeof(line));
        cout<<line<<endl;}
        source.close();
    }
}
		
	posted on 2006-05-30 01:38 
Jerry Cat 阅读(743) 
评论(1)  编辑 收藏 引用