aboutsummaryrefslogtreecommitdiffstats
path: root/showerror.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'showerror.cpp')
-rw-r--r--showerror.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/showerror.cpp b/showerror.cpp
new file mode 100644
index 0000000..73ba0fa
--- /dev/null
+++ b/showerror.cpp
@@ -0,0 +1,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