Blagodarenko / XPlotter

CPU plotter for BURST
GNU General Public License v3.0
54 stars 26 forks source link

Write errors to stderr #19

Closed ohager closed 6 years ago

ohager commented 6 years ago

Hi Blago,

another user encountered an issue with my autoplotter. For some reason XPlotter exited unsuccessfully, and returned a code only. It would be cewl if you could write your exceptions to stderr, such that it'll be easier to get the entire error messages.

Blagodarenko commented 6 years ago

or we can use something like: https://github.com/Blagodarenko/miner-burst/blob/master/miner.cpp#L286 /* LPSTR DisplayErrorText( DWORD dwLastError ) {

pragma warning(suppress: 6102)

HMODULE hModule = nullptr; // default to system source 
LPSTR MessageBuffer = nullptr; 
DWORD dwBufferLength; 
DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM ;
if(dwLastError >= NERR_BASE && dwLastError <= MAX_NERR) 
{ 
    hModule = LoadLibraryEx( TEXT("netmsg.dll"), nullptr, LOAD_LIBRARY_AS_DATAFILE );
    if(hModule != nullptr) dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
} 
dwBufferLength = FormatMessageA(dwFormatFlags, hModule, dwLastError, MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT), (LPSTR)&MessageBuffer, 0, nullptr);
if(hModule != nullptr) FreeLibrary(hModule); 
return MessageBuffer;

} */

ohager commented 6 years ago

Haha, I didn't get the idea of that code... could you explain me the intend of that piece?! std::fprintf(std::stderr, ...) is IMHO much clearer.

Blagodarenko commented 6 years ago

that piece translate errorcode to text info for default language (EN/RU/DE/ES/...)

ohager commented 6 years ago

Gotcha. That way you won't even write your own messages, but use those provided by the OS.

ohager commented 6 years ago

PR was merged. Closing issue.