Author Topic: Are error values put on a particular register?  (Read 6114 times)

Offline hhh3h

  • Jr. Member
  • *
  • Posts: 41
Are error values put on a particular register?
« on: October 19, 2011, 08:26:16 PM »
Greetings,

A while ago I was reading a topic on Wikipedia or some other website discussing calling conventions and function return values.

If I recall correctly, I was under the impression that (in a High Level Language) if a function "throws" an exception, what really happens (on the low-level) is that a value is placed into a special register that the caller checks upon ret to see if an error number (anything besides zero) was passed.

However, I cannot find this info to confirm this or read more about it, and I'm sure you can understand that it is very hard to make Internet searches containing the words "error" or "exception" and find anything generic about how they work.  Instead, all I can seem to find are results filled with people experiencing specific errors and exceptions.

So I was wondering if someone here could explain the error-throwing process (in general / or in brief) or help me find an informational topic about it.  I am not an assembly programmer; I just have a curiosity in low-level programming and it's something I may try to learn in the future.

Thank you.

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Are error values put on a particular register?
« Reply #1 on: October 20, 2011, 12:45:26 AM »

In the C calling convention the return code is "usually" stored in the eax register.
For exception handling it is drastically different.
To explain how it works at the assembler level I'll just direct you to this article:
How a C++ compiler implements Exception Handling.

Offline hhh3h

  • Jr. Member
  • *
  • Posts: 41
Re: Are error values put on a particular register?
« Reply #2 on: October 20, 2011, 04:52:18 PM »
Thank you, that is a very informative article.

After beginning to read it, I already see that my original concept of exception values being "returned" from functions is completely wrong.