How does (throw Exception) and (return value) is implemented in a Language such as Java or C#? I want to know the mechanism how its support is included in a Language and not just the usage of try { .... } catch (Exception) {} ?
We know when we call a function i.e.
public void doSomething() { .... .... return; }
Then on the call is put on the stack and when the method returns the call to doSomething on stack pops out.
What happened in the case when return statement returns with a value say return 4; the call to doSomething() on the stack pops out and the next statement on Prog counter got processed. What happened with the returned value where it got saved and how it's utilized.
======================================================
Similarly in the case of exception throw the throw ex; statement finds on the stack the appropriate catch statement and untill it finds it, it keeps popping things outa stack... How this machenism works??