C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Policy for Error genration.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Seweryn Habdank-Wojewódzk
Guest





PostPosted: Tue Jun 27, 2006 4:27 pm    Post subject: Policy for Error genration. Reply with quote



Hi

Did anyone think about creation of the policy classes for genrating
Errors?

Generally there are in C++ 3 methods:

1. Old from C.
return "value of the error".

2. assert() or //or boost assertions

3. exceptions

Below is my proposition of the code for that purpose, but in my opinion
should be better solution for it, because there is too much copy of the
code in it.

foo < typename Condition_type, typename Error_policy >
{};

// class belo should be changed in macro with parameter "text"
template <
typename first_type,
typename second_type,
typename Binary_operation
Quote:

struct Condition

{
/* macro is important here
*/
std::string text = "My condition";
std::string what()
{
return ( (text + "is not fulfill.") );
};

bool operator( first_type lhs, second_type rhs)
{
return ( Binary_operation ( lhs, rhs ) );
}
};

struct None_error_policy {};
struct Old_C_error_policy {};
struct Assert_policy {};
struct Exception_policy<typename Exception_type>
{ typedef Exception_type exception_type };

template< typename Condition_type >
struct foo < Condition_type, None_error_policy >
{
int operator() throw()
{}
};

template< typename Condition_type >
struct foo < Condition_type, Old_C_error_policy >
{
int operator() throw()
{
if ( Condition_type ( x, y ) )
{
return 1;
}
else
{
return 0;
}
}
};

template< typename Condition_type >
struct foo < Condition_type, Assert_policy >
{
int operator() throw()
{
assert ( Condition_type ( x, y ) );
return 0;
}
};

template< typename Condition_type >
struct foo < Condition_type, Exception_policy >
{
int operator() throw ( typename
Exception_policy::exception_type )
{
if ( Condition_type(x,y) )
{
throw typename Exception_policy::exception_type
(
Condition_type.what()
);
}
return 0;
}
};

Best regards.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.