Exception Handling

Discussion in 'Mac Programming' started by blueshogun96, Jan 4, 2013.

  1. macrumors member

    Nov 24, 2012
    I've done lots of searching on this, but haven't found what I needed. I'm trying to write an exception handler for MacOSX, but all I've found information on is std::exception and some really obscure examples on NSException.

    What I need is have the exact memory location (or should I say, the value of the EIP or RIP register) and the value of the x86 registers when the exception occurs as well as the exception code. Maybe this functionality isn't available on MacOSX, but this is what I've gotten used to using on Windows (yeah, I'm spoiled). Am I missing something? Thanks.

  2. macrumors G5


    Nov 25, 2005
    It looks like you are talking about hardware interrupts, not exceptions.

    If you are talking about exceptions, you'll never see and you'll never need to see any processor registers. Read up about try / catch / throw in C++ and @trye etc. in Objective-C.
  3. macrumors 604


    Nov 26, 2007
    My understanding is that exception handling is rarely done in Obj-C, because far fewer things throw exceptions (instead they do things like return null. 0, -1, or an enum value labeled exception.)
    Exception handling leads to messy, hard to follow code that runs (relatively) slow.
  4. macrumors G5


    Nov 25, 2005
    In Objective-C, any exception that is thrown should be considered a bug in your code. The only exception (sorry) to that rule is remote objects, where any call can potentially throw an exception.
  5. thread starter macrumors member

    Nov 24, 2012
    I understand how try, catch and throw work, but now that I look a bit deeper into the issue, Microsoft just has a special feature that allows the user to retain the values of the entire register set as well as the complete call stack, which is not part of standard exception handling.
  6. macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    Yes. Your goal.

    Explain the purpose so that others can understand why you think you need such low level information. Perhaps that will bring someone into the conversation with a great result.
  7. macrumors G5


    Nov 25, 2005
    backtrace and backtrace_symbols are standard BSD functions and work just fine on MacOS X. If you want the contents of all registers, you can just write an inline assembler function, but I can't quite see what that would be good for.
  8. macrumors 6502a

    May 10, 2009
    Des Moines, WA
    Perhaps a better explanation as to your goals are.

    My question is why you think you need this information?
    What do you "think" you need it?

    Are you doing user space programming or system (kernel) level programming?
  9. thread starter macrumors member

    Nov 24, 2012
    Okay, sorry for being so vague. I mentioned this in another thread, and I'm writing a cross platform Xbox emulator. So far, my approach works in Windows and Linux (as multiple people have confirmed), but so far, not on MacOSX.

    Since my goal is to use static-rec (or a variant of it at least), I'm required to use the host machine's CPU to a certain degree, and when debugging, obtaining the value of the CPU registers upon an exception occurrence is absolutely necessary.

    See above, but so far, it looks like a mix of user level and kernel level programming.

    See above, please.

Share This Page