in Education by
At least according to a description of Mono's exception handling implementation, all the x86 registers are saved when an exception is thrown. Besides the stack pointer (ESP), frame pointers (EBP), instruction pointers (EIP), and the register that holds the exception object, why are the other registers saved as well? Why save that the entire context when in .NET is there is no mechanism to continuing executing at the point immediately after a throw? UPDATE: EMCA states the following in section 12.3.2.4 Overview of exception handling: An exception object describing the exception is automatically created by the CLI and pushed onto the evaluation stack as the first item upon entry of a filter or catch clause. Execution cannot be resumed at the location of the exception, except with a filter handler. I don't know how the "except with a filter handler" can be accomplished in light of the previous statement. Also the description of the endfilter opcode only has two outcomes: "continue searching for another exception handler" or to execute the handler (which would execute another block of CIL opcodes.) It's missing a "resume" option. Therefore, I interpret this discrepancy in the specification to basically mean .NET does not support continuing executing at the point immediately after a throw. Maybe it was considered at some point but never fully realized and implemented. UPDATE 2: Someone pointed out that "resume" could simply happen if no filter handler opts to catch the exception. However, the specification for throw states: "the throw instruction throws the exception object on the stack and empties the stack." The emptying of the stack would make it impossible to execute the code immediately after the throw statement, as that code might require something on the stack. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You're looking at implementation details: they usually aren't a one to one match to the ECMA spec for many possible reasons (like ease of implementation, code sharing, providing additional semantics, future-proofing, optimizations etc). In this particular case there are several considerations. Mono performs exception handling based on a view of the processor state called MonoContext: as this structure is used also in other places, it contains all the relevant registers even if some may not be needed in some particular cases. In particular, exception handling can be initiated also from a cpu exception where all the registers need to be restored, so all of them are collected. Someone already observed that the context is used also for the debugger. Consider also the case of a method with a try/catch with the catch being a simple local var setting. Now, an advanced register allocator might put a local var that is used both before the throw (note the throw may be implicit, like a null reference, so handled by the cpu exception path) and after the catch in a register like edx. If you don't save all the registers at the throw/exception point you corrupted the program state as edx would get overwritten during exception handling. As a last comment: are you worried that saving the few extra registers is wasting cpu cycles? If you actually count the cycles spent, they are completely in the noise wrt all the stuff that needs to happen during exception handling.

Related questions

0 votes
    Before and during the processing the data is stored on 1 registers 2 cache Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    What is Exception Handling in WCF? What are the ways for WCF Exception Handling?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    Which of these keywords is not a part of exception handling? (a) try (b) finally (c) thrown (d) ... Exception Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    The question is: after am raising an exception, can I stop it to propagate from it's own constructor ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    The question is: after am raising an exception, can I stop it to propagate from it's own constructor ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Which of these keywords is not a part of exception handling? (a) try (b) finally (c) thrown (d) ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Explain about SAP ABAP - Exception Handling?...
asked Oct 18, 2020 in Technology by JackTerrance
0 votes
    Explain about the problems which you have faced during your past experience while handling mobile application testing programs in the Cloud environment?...
asked Feb 7, 2021 in Technology by JackTerrance
0 votes
    In __________, each external request is tagged with a unique identifier which is passed to all services involved ... . Distributed tracing C. Application logging D. Audit logging...
asked Jan 11, 2023 in Education by JackTerrance
0 votes
    Which of these packages contains all the classes and methods required for even handling in Java? (a) java.applet ... Handling of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which of these packages contains all the event handling interfaces? (a) java.lang (b) java.awt (c) java.awt ... Event Handling of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which of the interface contains all the methods used for handling thread related operations in Java? (a) ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of these packages contains all the event handling interfaces? (a) java.lang (b) java.awt (c ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    In __________, each external request is tagged with unique identifier which is passed to all services involved in ... b)Audit logging (c)Application logging (d)Exception tracing...
asked Oct 21, 2020 in Technology by Editorial Staff
...