try and catch mechanism question

Hi
I would like to add try catch mechanism to the driver in order to catch (for testing purpose)
SYSTEM_THREAD_EXCEPTION_NOT_HANDLED (7e) ; (NTSTATUS) 0xc0000005
I followed the sample code
http://www.osronline.com/article.cfm?article=58,
First stage I would like to handle any exception generated (Followed figure 1,2) but i still get a BSOD,Can anyone post sample code that will work.
For example
__try {
DbgPrint(“Test Code\n”);
PCHAR buffer = ExAllocatePool(NonPagedPool, 10);
ExFreePool(buffer);
ExFreePool(buffer);
} __except (EXCEPTION_EXECUTE_HANDLER) {
DbgPrint(“Exception is 0x%x\n”, GetExceptionCode());
return FALSE;
}

Short answer: don’t do this. SEH (structured exception handling, vastly different than C++ EH) is meant for very very limited scenarios, not a catch all.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Wednesday, November 25, 2015 10:47 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] try and catch mechanism question

Hi
I would like to add try catch mechanism to the driver in order to catch (for testing purpose) SYSTEM_THREAD_EXCEPTION_NOT_HANDLED (7e) ; (NTSTATUS) 0xc0000005 I followed the sample code https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Farticle.cfm%3Farticle%3D58%2C&data=01|01|Doron.Holan%40microsoft.com|6a757917f7aa478c3bf908d2f5c8c4f7|72f988bf86f141af91ab2d7cd011db47|1&sdata=dzPPIA3eV9v3gsIINp%2F8Fp7Q35ogU%2B4nqLE2WHS8TNg%3D
First stage I would like to handle any exception generated (Followed figure 1,2) but i still get a BSOD,Can anyone post sample code that will work.
For example
__try {
DbgPrint(“Test Code\n”);
PCHAR buffer = ExAllocatePool(NonPagedPool, 10);
ExFreePool(buffer);
ExFreePool(buffer);
}__except (EXCEPTION_EXECUTE_HANDLER) {
DbgPrint(“Exception is 0x%x\n”, GetExceptionCode());
return FALSE;
}


NTDEV is sponsored by OSR

Visit the list at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fshowlists.cfm%3Flist%3Dntdev&data=01|01|Doron.Holan%40microsoft.com|6a757917f7aa478c3bf908d2f5c8c4f7|72f988bf86f141af91ab2d7cd011db47|1&sdata=fteLHwAxxlgVwvMmhS7keNOmL77UnX0yH1hI08vh4no%3D

OSR is HIRING!! See https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osr.com%2Fcareers&data=01|01|Doron.Holan%40microsoft.com|6a757917f7aa478c3bf908d2f5c8c4f7|72f988bf86f141af91ab2d7cd011db47|1&sdata=uDT0pxgL2SDQ20YdLSRneSX%2FS9sBfInZoUZ5LMNrNGE%3D

For our schedule of WDF, WDM, debugging and other seminars visit:
https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osr.com%2Fseminars&data=01|01|Doron.Holan%40microsoft.com|6a757917f7aa478c3bf908d2f5c8c4f7|72f988bf86f141af91ab2d7cd011db47|1&sdata=3awvEvxWFrTH%2FQSCGCnL9KnJy2%2FUeeGfd0WlwubdbEA%3D

To unsubscribe, visit the List Server section of OSR Online at https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fpage.cfm%3Fname%3DListServer&data=01|01|Doron.Holan%40microsoft.com|6a757917f7aa478c3bf908d2f5c8c4f7|72f988bf86f141af91ab2d7cd011db47|1&sdata=r2wkVXktdsBYMSbrDe%2BcLlYq1DkCOMjXk7N3ay%2Fun1w%3D

Why? you’re just masking a bug away (so it will do more harm) instead of fixing it.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Hi
> I would like to add try catch mechanism to the driver in order to catch (for testing purpose)
> SYSTEM_THREAD_EXCEPTION_NOT_HANDLED (7e) ; (NTSTATUS) 0xc0000005
> I followed the sample code
> http://www.osronline.com/article.cfm?article=58,
> First stage I would like to handle any exception generated (Followed figure 1,2) but i still get a BSOD,Can anyone post sample code that will work.
> For example
> __try {
> DbgPrint(“Test Code\n”);
> PCHAR buffer = ExAllocatePool(NonPagedPool, 10);
> ExFreePool(buffer);
> ExFreePool(buffer);
> }__except (EXCEPTION_EXECUTE_HANDLER) {
> DbgPrint(“Exception is 0x%x\n”, GetExceptionCode());
> return FALSE;
> }
>
>