Commit f2326a37 authored by chili's avatar chili
Browse files

info only exception

parent caca4839
......@@ -14,10 +14,12 @@ namespace wrl = Microsoft::WRL;
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO(hrcall) infoManager.Set(); if( FAILED( hr = (hrcall) ) ) throw GFX_EXCEPT(hr)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO_ONLY(call) infoManager.Set(); (call); {auto v = infoManager.GetMessages(); if(!v.empty()) {throw Graphics::InfoException( __LINE__,__FILE__,v);}}
#else
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO(hrcall) GFX_THROW_NOINFO(hrcall)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO_ONLY(call) (call)
#endif
......@@ -129,7 +131,7 @@ void Graphics::DrawTestTriangle()
const UINT offset = 0u;
pContext->IASetVertexBuffers( 0u,1u,&pVertexBuffer,&stride,&offset );
pContext->Draw( 3u,0u );
GFX_THROW_INFO_ONLY( pContext->Draw( 3u,0u ) );
}
......@@ -201,3 +203,40 @@ const char* Graphics::DeviceRemovedException::GetType() const noexcept
{
return "Chili Graphics Exception [Device Removed] (DXGI_ERROR_DEVICE_REMOVED)";
}
Graphics::InfoException::InfoException( int line,const char * file,std::vector<std::string> infoMsgs ) noexcept
:
Exception( line,file )
{
// join all info messages with newlines into single string
for( const auto& m : infoMsgs )
{
info += m;
info.push_back( '\n' );
}
// remove final newline if exists
if( !info.empty() )
{
info.pop_back();
}
}
const char* Graphics::InfoException::what() const noexcept
{
std::ostringstream oss;
oss << GetType() << std::endl
<< "\n[Error Info]\n" << GetErrorInfo() << std::endl << std::endl;
oss << GetOriginString();
whatBuffer = oss.str();
return whatBuffer.c_str();
}
const char* Graphics::InfoException::GetType() const noexcept
{
return "Chili Graphics Info Exception";
}
std::string Graphics::InfoException::GetErrorInfo() const noexcept
{
return info;
}
......@@ -27,6 +27,16 @@ public:
HRESULT hr;
std::string info;
};
class InfoException : public Exception
{
public:
InfoException( int line,const char* file,std::vector<std::string> infoMsgs ) noexcept;
const char* what() const noexcept override;
const char* GetType() const noexcept override;
std::string GetErrorInfo() const noexcept;
private:
std::string info;
};
class DeviceRemovedException : public HrException
{
using HrException::HrException;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment