[ create a new paste ] login | about

Link: http://codepad.org/sPFLKHC1    [ raw code | fork ]

C++, pasted on Jul 30:
/*
 * By Murilo Adriano Vasconcelos (C) 2010
 * http://murilo.wordpress.com
 */

#include <cassert>
#include "policies.hpp"
#include "divide.hpp"

int main()
{	
	using namespace policies;
	
	assert((divide(1, 0) == 0));
	typedef domain_error<errno_on_error> errno_pol;
	typedef domain_error<ignore_error>   ignore_pol;
	typedef domain_error<throw_on_error> throw_pol;
	
	// Testing errno_on_error policy
	errno = 0;
	divide(1, 0, errno_pol());
	assert((errno == EDOM));
	
	// Testing ignore_error policy
	assert((divide(1, 0, ignore_pol()) == 0));
	
	// Testing throw_on_error policy
	try {
		divide(1, 0, throw_pol());
		
		// Never is threw
		throw "error 0";
	}
	catch (std::domain_error&) {
		// FINE!!!
	}
	catch (...) {
		throw "error 1";
	}
	
	return 0;
}


Create a new paste based on this one


Comments: