flat assembler
Message board for the users of flat assembler.

Index > Main > FASM and exceptions

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 19 Jun 2018, 16:12
Hello,
I would like to know if it was possible to design an exception system in FASM.
For example, something like that:
Code:
void foo() {
    try {
        throw 65;
    } catch(int ex) {

    }
}
    

How could this be transcribed into FASM? One could, I guess, write something that looks like this:
Code:
foo:
    push ebp
    mov ebp, esp
    mov dword eax, 65
foo_catch:
    ; eax contains the thrown
    

But that doesn't seem to me very "solid" as a model, nor even adapted to potential more consequent exceptions, such as stack overflow, bad memory access, ...
Do you have any ideas Smile ?
Thank you!

_________________
The best way to predict the future is to invent it.
Post 19 Jun 2018, 16:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20482
Location: In your JS exploiting you and your system
revolution 19 Jun 2018, 16:26
You have to ask to OS to forward exceptions to your code. So the code will be OS dependant.
Post 19 Jun 2018, 16:26
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 20 Jun 2018, 09:33
I'm afraid I don't quite understand what you mean by that.
Also, here's a little test I did in C++ to see how this language handled exceptions, and unless I'm wrong, there's no[real] OS dependency, here's :

Image

_________________
The best way to predict the future is to invent it.
Post 20 Jun 2018, 09:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20482
Location: In your JS exploiting you and your system
revolution 20 Jun 2018, 09:48
All those calls to external functions are the C-library OS interface routines.

You won't be able to get any exceptions unless you ask the OS to pass them to your code. All exceptions trap into the kernel. This is done by the CPU and there is no way to alter that from user code. So you have to know which OS you are using and from there how to interface with the OS to get the exceptions.
Post 20 Jun 2018, 09:48
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 20 Jun 2018, 10:18
Ha, okay, thanks, I understand better. So I'll see what I can do.
Thank you Wink
Post 20 Jun 2018, 10:18
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2582
Furs 20 Jun 2018, 15:23
At your skill level, you should definitely not bother with exceptions. They're really horrendous and a pain to handle, especially on x64 Windows, but even the 32-bit SEH is somewhat of a pain in the arse.

I don't know about other OSes.
Post 20 Jun 2018, 15:23
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 20 Jun 2018, 15:42
Especially for Windows, you can see the seh.fpr example from Fresh IDE package. The FreshLib library contains macros that make the usage of SEH pretty easy. The definitions of the macros are in the file: freshlib/macro/Win32/_exceptions.inc. You can see that the code behind is not so complex. Smile
Post 20 Jun 2018, 15:42
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 20 Jun 2018, 15:54
That's exactly what I was thinking :p . Exceptions, especially at my level, isn't easy.
Post 20 Jun 2018, 15:54
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 20 Jun 2018, 16:13
They’re difficult at all levels. Exceptions are not only about handling. They’re about proper design and about having your data structures ready for an exception to occur literally in every line of your code.
Post 20 Jun 2018, 16:13
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.