aboutsummaryrefslogtreecommitdiffstats
path: root/showerror.cpp
blob: 73ba0faa003da01d35787eaaae61a1098bd5af0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// showerror.cpp
// Revision 9-jan-2005

#include "showerror.h"

#include "blassic.h"

#include "error.h"

#include "trace.h"

#include <iostream>
using std::cerr;
using std::endl;

#ifdef BLASSIC_USE_WINDOWS

#include <windows.h>

void showlasterror ()
{
	TRACEFUNC (tr, "showlasterror");

	if (! showdebuginfo () )
		return;

	char * lpMsgBuf;
	DWORD r= FormatMessage (
		FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		GetLastError (),
		MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
		(char *) & lpMsgBuf,
		0,
		NULL);
	if (r)
	{
		TRMESSAGE (tr, lpMsgBuf);
		CharToOemBuff (lpMsgBuf, lpMsgBuf, r);
		try
		{
			cerr << lpMsgBuf << endl;
		}
		catch (...)
		{
			r= 0;
		}
		LocalFree (lpMsgBuf);
	}
	if (! r)
	{
		static const char FAILED []=
			"FormatMessage failed, can't show error info";
		TRMESSAGE (tr, FAILED);
		cerr << FAILED << endl;
	}
}

#else

#include <string.h>
#include <errno.h>

void showlasterror ()
{
	TRACEFUNC (tr, "showlasterror");

	if (! showdebuginfo () )
		return;

	const char * message= strerror (errno);
	TRMESSAGE (tr, message);
	cerr << message << endl;
}

#endif

void showlasterror (const char * str)
{
	TRACEFUNC (tr, "showlasterror (str)");

	if (! showdebuginfo () )
		return;

	cerr << str << ": ";
	showlasterror ();
}

// End of showerror.cpp
Un proyecto texto-plano.xyz