]> gitweb.factorcode.org Git - factor.git/commitdiff
windows.errors: streamline error handling and throwing
authorAlexander Iljin <ajsoft@yandex.ru>
Tue, 28 Jun 2016 22:55:15 +0000 (01:55 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 25 Nov 2019 15:06:59 +0000 (07:06 -0800)
basis/windows/errors/authors.txt
basis/windows/errors/errors.factor

index 7c1b2f22790bfdca05f14a555a40b7eaa3ce2abd..d652f68ac871fb0bf59a892373e3b1cbfccc4183 100644 (file)
@@ -1 +1,2 @@
 Doug Coleman
+Alexander Ilin
index f5e5314e2f6d1d629177c18977a2590eebaefa8b..ffb735be08774ca5176dc1c57bc5f58710f5f933 100644 (file)
@@ -719,23 +719,18 @@ CONSTANT: FORMAT_MESSAGE_MAX_WIDTH_MASK   0x000000FF
 
 ERROR: windows-error n string ;
 
-: (win32-error) ( n -- )
-    [ dup win32-error-string windows-error ] unless-zero ;
+: throw-windows-error ( n -- * )
+    dup n>win32-error-string windows-error ;
 
-: win32-error ( -- )
-    GetLastError (win32-error) ;
+: n>win32-error-check ( n -- )
+    [ throw-windows-error ] unless-zero ;
 
+! Note that win32-error* words throw GetLastError code.
+: win32-error ( -- ) GetLastError n>win32-error-check ;
 : win32-error=0/f ( n -- ) { 0 f } member? [ win32-error ] when ;
 : win32-error>0 ( n -- ) 0 > [ win32-error ] when ;
 : win32-error<0 ( n -- ) 0 < [ win32-error ] when ;
-: win32-error<>0 ( n -- ) zero? [ win32-error ] unless ;
-
-: n>win32-error-check ( n -- )
-    dup ERROR_SUCCESS = [
-        drop
-    ] [
-        dup n>win32-error-string windows-error
-    ] if ;
+: win32-error<>0 ( n -- ) [ win32-error ] unless-zero ;
 
 : check-invalid-handle ( handle -- handle )
     dup INVALID_HANDLE_VALUE = [ win32-error ] when ;