Windows Error handling

Hi Everyone,

the NT_SUCCESS macro is defined in ntdef.h as:

#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)

and all Windows status codes (STATUS_xxxx) are
positive values as defined in ntstatus.h.

How do you handle an error? For example, the following
code will never be able to handle an error case, since
status codes (STATUS_xxxx) are all positive.

NTSTATUS status = Function(…);
if (!NT_SUCCESS(status))
{
// handle error;

}

This is so simple but I don’t get it. Would someone
clarify for me?

Thanks


Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine’s Day
http://shopping.yahoo.com

No, All Error status codes are NEGATIVE, the real errors start
at 0x80000000 that is negative as a LONG value which is the
defininition of NTSTATUS.

Don Burn
Windows 2k/XP/2k3 Filesystem and Driver Consulting

----- Original Message -----
From: “John Chan”
To: “NT Developers Interest List”
Sent: Monday, February 17, 2003 12:21 PM
Subject: [ntdev] Windows Error handling

> Hi Everyone,
>
> the NT_SUCCESS macro is defined in ntdef.h as:
>
> #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
>
> and all Windows status codes (STATUS_xxxx) are
> positive values as defined in ntstatus.h.
>
> How do you handle an error? For example, the following
> code will never be able to handle an error case, since
> status codes (STATUS_xxxx) are all positive.
>
> NTSTATUS status = Function(…);
> if (!NT_SUCCESS(status))
> {
> // handle error;
>
> }
> …
>
> This is so simple but I don’t get it. Would someone
> clarify for me?
>
> Thanks
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Shopping - Send Flowers for Valentine’s Day
> http://shopping.yahoo.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@acm.org
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Yes well the same file has: typedef LONG NTSTATUS;
Values like 0xC0000001 are negative.

-----Original Message-----
From: John Chan [mailto:xxxxx@yahoo.com]
Sent: Monday, February 17, 2003 12:21 PM
To: NT Developers Interest List
Subject: [ntdev] Windows Error handling

Hi Everyone,

the NT_SUCCESS macro is defined in ntdef.h as:

#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)

and all Windows status codes (STATUS_xxxx) are
positive values as defined in ntstatus.h.

How do you handle an error? For example, the following
code will never be able to handle an error case, since
status codes (STATUS_xxxx) are all positive.

NTSTATUS status = Function(…);
if (!NT_SUCCESS(status))
{
// handle error;

}

This is so simple but I don’t get it. Would someone
clarify for me?

Thanks


Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine’s Day http://shopping.yahoo.com


You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

Not true. Remember that negative numbers are represented with the high
bit set. From ntstatus.h:

// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
// ±–±±±----------------------±------------------------------+
// |Sev|C|R| Facility | Code |
// ±–±±±----------------------±------------------------------+
//
// where
//
// Sev - is the severity code
//
// 00 - Success
// 01 - Informational
// 10 - Warning
// 11 - Error

So warning and error codes are negative and the test will fail.

Thanks to Don, Mark and Mays.
I did not see the LONG.
Thanks

— “Roddy, Mark” wrote:
> Yes well the same file has: typedef LONG NTSTATUS;
> Values like 0xC0000001 are negative.
>
> -----Original Message-----
> From: John Chan [mailto:xxxxx@yahoo.com]
> Sent: Monday, February 17, 2003 12:21 PM
> To: NT Developers Interest List
> Subject: [ntdev] Windows Error handling
>
>
> Hi Everyone,
>
> the NT_SUCCESS macro is defined in ntdef.h as:
>
> #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
>
> and all Windows status codes (STATUS_xxxx) are
> positive values as defined in ntstatus.h.
>
> How do you handle an error? For example, the
> following
> code will never be able to handle an error case,
> since
> status codes (STATUS_xxxx) are all positive.
>
> NTSTATUS status = Function(…);
> if (!NT_SUCCESS(status))
> {
> // handle error;
>
> }
> …
>
> This is so simple but I don’t get it. Would someone
> clarify for me?
>
> Thanks
>
>
>
> Do you Yahoo!?
> Yahoo! Shopping - Send Flowers for Valentine’s Day
> http://shopping.yahoo.com
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To
> unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com


Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine’s Day
http://shopping.yahoo.com

Be careful if you are using 98ddk ndis.h.
NTSTATUS is defined to NDIS_STATUS and
NDIS_STATUS is defined to ULONG.

This got me once.

-Srin.

-----Original Message-----
From: John Chan [mailto:xxxxx@yahoo.com]
Sent: Monday, February 17, 2003 10:15 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Windows Error handling

Thanks to Don, Mark and Mays.
I did not see the LONG.
Thanks

— “Roddy, Mark” wrote:
> Yes well the same file has: typedef LONG NTSTATUS;
> Values like 0xC0000001 are negative.
>
> -----Original Message-----
> From: John Chan [mailto:xxxxx@yahoo.com]
> Sent: Monday, February 17, 2003 12:21 PM
> To: NT Developers Interest List
> Subject: [ntdev] Windows Error handling
>
>
> Hi Everyone,
>
> the NT_SUCCESS macro is defined in ntdef.h as:
>
> #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
>
> and all Windows status codes (STATUS_xxxx) are
> positive values as defined in ntstatus.h.
>
> How do you handle an error? For example, the
> following
> code will never be able to handle an error case,
> since
> status codes (STATUS_xxxx) are all positive.
>
> NTSTATUS status = Function(…);
> if (!NT_SUCCESS(status))
> {
> // handle error;
>
> }
> …
>
> This is so simple but I don’t get it. Would someone
> clarify for me?
>
> Thanks
>
>
>
> Do you Yahoo!?
> Yahoo! Shopping - Send Flowers for Valentine’s Day
> http://shopping.yahoo.com
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To
> unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com


Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine’s Day
http://shopping.yahoo.com


You are currently subscribed to ntdev as: xxxxx@nai.com
To unsubscribe send a blank email to xxxxx@lists.osr.com