当前位置: 首页>>代码示例>>C++>>正文


C++ Exception::htmlMessage方法代码示例

本文整理汇总了C++中Exception::htmlMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ Exception::htmlMessage方法的具体用法?C++ Exception::htmlMessage怎么用?C++ Exception::htmlMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::htmlMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fallbackErrorPage

void RequestError::fallbackErrorPage(Request* request,
                                     const Exception& e,
                                     const String& e2Name)
{
	if (!request->headersSent())
	{
		request->setStatus(500);
		request->sendHeaders();
	}
	request->stream() << "<h1>“" << e.type().htmlEscape() << "” exception</h1>"
	                  << "<p>" << e.htmlMessage() << "</p>"
	                  << "<p><strong>Additionally, a “" << e2Name
	                  << "” exception was encountered while handling the "
	                  << "exception.</strong></p>"
	                  << "<h2>Stack trace</h2><ol start=\"0\">";
	List<StackTrace::Frame> stack = e.stackTrace()->stackFrames();
	for (const StackTrace::Frame& frame : stack)
	{
		request->stream() << "<li><strong><code>" << frame.function.htmlEscape()
		                  << "</code></strong> (<code>0x"
		                  << String::fromNumber(frame.address, 16)
		                  << "</code>)<br />"
		                  << "<small>in <code>" << frame.object.relativePath()
		                  << "</code>, file <code>" << frame.fileName
		                  << "</code>, line " << frame.line << "</small></li>";
	}
	request->stream() << "</ol>";
}
开发者ID:dreamsxin,项目名称:WebCpp,代码行数:28,代码来源:RequestError.cpp

示例2: exception

void RequestError::exception(Request* request, Exception& e)
{
	int code = 500;
	if (e.type() == "NotFound")
		code = 404;
	else if (e.type() == "Forbidden")
		code = 403;

	if (code == 404)
		System::log("NotFound", e.message(), request->ip());
	else if (code == 403)
		System::log("Forbidden", e.message(), System::Warning, request->ip());
	else
		System::log("Exceptions",
		            String("“%1” exception: %2.").format({e.type(), e.message()}),
		            System::Warning, request->ip());

#ifndef DEBUG
	if (!request->headersSent())
		request->setStatus(code);
	Template* tpl = new Template("Errors/" + String(code) + ".html",
	                             nullptr, request);
	tpl->render();
	delete tpl;
	return;
#endif

	try
	{
		View tpl = new Template("Sys::Exception.html", nullptr, request);

		tpl["exceptionName"] = e.type();
		tpl["exceptionMessage"] = e.htmlMessage();
		tpl["webcppVersion"] = System::get()->version();
		tpl["serverName"] = request->env("SERVER_NAME", "");
		loadStackTrace(e, dynamic_cast<Template*>(*tpl));

		if (!request->headersSent())
			request->setStatus(500);
		tpl->render();
	}
	catch (const Exception& e2)
	{ fallbackErrorPage(request, e, e2.type()); }
	catch (const std::exception& e2)
	{ fallbackErrorPage(request, e, typeid(e2).name()); }
}
开发者ID:dreamsxin,项目名称:WebCpp,代码行数:46,代码来源:RequestError.cpp


注:本文中的Exception::htmlMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。