From: Alexander Iljin Date: Tue, 28 Jun 2016 22:55:15 +0000 (+0300) Subject: windows.errors: streamline error handling and throwing X-Git-Tag: 0.99~3583 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=049356574a1087eb50c054e018c7104b84407318 windows.errors: streamline error handling and throwing --- diff --git a/basis/windows/errors/authors.txt b/basis/windows/errors/authors.txt index 7c1b2f2279..d652f68ac8 100644 --- a/basis/windows/errors/authors.txt +++ b/basis/windows/errors/authors.txt @@ -1 +1,2 @@ Doug Coleman +Alexander Ilin diff --git a/basis/windows/errors/errors.factor b/basis/windows/errors/errors.factor index f5e5314e2f..ffb735be08 100644 --- a/basis/windows/errors/errors.factor +++ b/basis/windows/errors/errors.factor @@ -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 ;