flat assembler
Message board for the users of flat assembler.
Index
> Windows > How does try/catch works at assembly level? |
Author |
|
Teehee 21 Jul 2010, 11:39
Code: try { } catch (Exception) { } _________________ Sorry if bad english. |
|||
21 Jul 2010, 11:39 |
|
Teehee 21 Jul 2010, 11:47
wow, thats so big.. but i can't understand macros yet.
|
|||
21 Jul 2010, 11:47 |
|
revolution 21 Jul 2010, 13:29
It is probably easier just to make your code correct and never generate exceptions.
Try/catch is the only way I know of to use into in a Windows proggy. But who ever used it anyway even in the DOS days when you could? |
|||
21 Jul 2010, 13:29 |
|
revolution 21 Jul 2010, 13:32
BTW: did you know that the WM_TIMER callback is run under the API try/catch block? This means you can't use int3 to trigger a debugger, it gets swallowed by the handler and your proggy continues to run.
|
|||
21 Jul 2010, 13:32 |
|
vid 21 Jul 2010, 14:11
Most often I have seen try/catch implemented in C using setjmp() / longjmp() mechanism.
Basically you just save stack pointer and address where to jump on every "try", stack up these structures, and on exception go back over them until you find appropriate catch for the type of exception that was thrown. This becomes useful when you have ability to automatically call "destructors" of objects that needs some extra code upon release (like open file handles, allocated memory, etc.). This is not very much possible to do (in sane way) in ASM or C, and so try/catch isn't used so often either. |
|||
21 Jul 2010, 14:11 |
|
revolution 21 Jul 2010, 15:21
vid wrote: Most often I have seen try/catch implemented in C using setjmp() / longjmp() mechanism. |
|||
21 Jul 2010, 15:21 |
|
vid 21 Jul 2010, 15:52
Depends on implementation
Supposing we are speaking of Windows, I never checked. However, I saw it used somewhere in HAL.DLL, and I am not really so sure SEH can be used there. In userland, my guess would be SEH is used. |
|||
21 Jul 2010, 15:52 |
|
b1528932 21 Jul 2010, 23:16
in userland, exceptions will NEVER occur. And if they do there is nbothing u can do about them, just kill the app.
In kernel mode however, its diffrent story. Windows provide SEH. structure at address 0 holds NT_TIB, and NT_TIB holds exception records. each one is called by exception handler (well not exactly, exception handler return control to userland first, then userland function calls them). If they return something - next is invoked, if theyt return something else - execution is halted. you have to change ip/registers manually to fix the exception issue. |
|||
21 Jul 2010, 23:16 |
|
revolution 22 Jul 2010, 00:03
b1528932 wrote: in userland, exceptions will NEVER occur. b1528932 wrote: And if they do there is nbothing u can do about them, just kill the app. |
|||
22 Jul 2010, 00:03 |
|
baldr 25 Aug 2010, 09:20
Teehee,
There are try/catch and __try/__catch. They are different. Matt Pietrek described them in MSJ June 1997 "Under the hood" column; OpenRCE contains fine article about MSVC implementation details. |
|||
25 Aug 2010, 09:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.