D
dragon9
I want to write some small programs with exception safety, but I don't how
to write. Because my programs wrap C-api function( example: win32 api). I
don't find my direction. I wish any hot heart man to help me. My english is
too bad. I am sorry! Thanks!
#include "windows.h"
#include <string>
//
#ifndef FILE1_H
#define FILE1_H
namespace wukexin{
//
std::string Fileattrib_to_str( const DWORD attrib );
//
std::string Filetime_to_str( const FILETIME* x );
//
class Cfile_information
{
public:
explicit Cfile_information(std::string fname){initializer(fname);};
//~Cfile_information(){destroyer();};
void print();
protected:
//friend ostream& operator<< (std:stream& os, const Cfile_information&
file);
private:
void initializer(std::string fname);
void destroyer();
bool destroySuccess_;
HANDLE hfile_;
std::string fname_;
WIN32_FIND_DATA file_;
};
}
#endif //file1.h
////////////////
file.cpp
//**
void Cfile_information::initializer(std::string fname){
WIN32_FIND_DATA file;
//std::cout<<fname<<"construct success!\n";
hfile_=FindFirstFile(fname.c_str(),&file_);
if(INVALID_HANDLE_VALUE == hfile_){
//std::cout<<"FindFirstFile(fname,&file) run error!\n"<<std::endl;
throw <<"FindFirstFile(fname,&file) run error!\n";
}
destroySuccess_=false;
}
//
Cfile_information::~Cfile_information(){
if( !destroySuccess_ ){
try{
destroyer();
}
catch(){
// codes
}
};
//**
to write. Because my programs wrap C-api function( example: win32 api). I
don't find my direction. I wish any hot heart man to help me. My english is
too bad. I am sorry! Thanks!
#include "windows.h"
#include <string>
//
#ifndef FILE1_H
#define FILE1_H
namespace wukexin{
//
std::string Fileattrib_to_str( const DWORD attrib );
//
std::string Filetime_to_str( const FILETIME* x );
//
class Cfile_information
{
public:
explicit Cfile_information(std::string fname){initializer(fname);};
//~Cfile_information(){destroyer();};
void print();
protected:
//friend ostream& operator<< (std:stream& os, const Cfile_information&
file);
private:
void initializer(std::string fname);
void destroyer();
bool destroySuccess_;
HANDLE hfile_;
std::string fname_;
WIN32_FIND_DATA file_;
};
}
#endif //file1.h
////////////////
file.cpp
//**
void Cfile_information::initializer(std::string fname){
WIN32_FIND_DATA file;
//std::cout<<fname<<"construct success!\n";
hfile_=FindFirstFile(fname.c_str(),&file_);
if(INVALID_HANDLE_VALUE == hfile_){
//std::cout<<"FindFirstFile(fname,&file) run error!\n"<<std::endl;
throw <<"FindFirstFile(fname,&file) run error!\n";
}
destroySuccess_=false;
}
//
Cfile_information::~Cfile_information(){
if( !destroySuccess_ ){
try{
destroyer();
}
catch(){
// codes
}
};
//**