2

What changes does it happen in the program when the exception is caught? How does thrown exception is caught in nearest catch block.

Abhinav Konda
  • 225
  • 1
  • 11
  • 2
    The stack is unwind until either a catch block is found, or the call stack comes to an end. *C Interfaces and Implementations* shows an implementation of exceptions in C using macros - it might be useful to read it. – Filipe Gonçalves Jun 19 '14 at 10:02
  • 2
    Question doesn't seem bad,I don't know how people downvote question like this??? My upvote for you @AbhinavKonda. – Am_I_Helpful Jun 19 '14 at 10:05
  • 1
    If you're asking what happens at runtime, the phrase 'in a compiler' is irrelevant. Your question is too broad to answer here. It's covered in many books. – user207421 Jun 19 '14 at 10:08
  • 2
    It's not that your question is bad or has been already answered here. It is just too broad and you do not show that you have made any research on your part. Ask about some specific compiler and environment, search on your own, show what you have found and someone will be glad to help you. Otherwise your question needs a book as an answer. – Eugene Podskal Jun 19 '14 at 10:15
  • @EJP I just want to know what happens in compiler when it finds exception. How does it deals it? (Internally More Abstract manner) Because every1 knows what happens in abstract manner. If possible give me links or material where I can understand. Thanks in advance – Abhinav Konda Jun 19 '14 at 11:02
  • @Eugene Podskeal I just want to know what happens in compiler when it finds exception. How does it deals it? (Internally More Abstract manner) – Abhinav Konda Jun 19 '14 at 11:02
  • 1
    Do you know how the exceptions are handled(implemented) during runtime in different environments? Try to begin with such question. There are a lot of information. Do you understand old gcc, modern gcc, VC++ exception handling for C++ , Windows SEH, JRM and .NET exceptions? If it is so you could really want to find about compiler designs that produces such mechanics. But otherwise you are just trying to jump too far. You should know how it works(from outer point of view) before you should try to understand how it is implemented. – Eugene Podskal Jun 19 '14 at 11:12
  • 1
    The answers to this question are relevant: http://stackoverflow.com/q/1331220/120163 – Ira Baxter Jun 24 '14 at 01:48
  • @AbhinavKonda *Nothing* happens in a compiler 'when it finds an exception'. It doesn't find exceptions. It compiles `try, catch,` and `throw` statements. Exceptions are thrown and handled at runtime. – user207421 Jun 24 '14 at 01:55

1 Answers1

2

Well, I tried implementing simple exception-handling in C 2 years ago. Let me show it to you.

https://github.com/dlarudgus20/CTryCatch

(In fact, I made the github repository to practice as soon as I saw you question - it's my first repository >o< Thank you to give me the opportunity to use github!)

ikh
  • 10,119
  • 1
  • 31
  • 70