Java Exception vs C++ Exceptions

后端 未结 6 1373
一向
一向 2021-01-12 01:15

Where are exceptions stored ? Stack, Heap. How is memory allocated and deallocated for Exceptions? Now if you have more than one exception which needs to be handled are the

6条回答
  •  春和景丽
    2021-01-12 02:01

    In Java, Exception extends Throwable which extends Object. i.e. from a memory point of view its an object just like any other.

    It has been suggested in Java 7 that local variables could be placed on the stack using escape analysis to find candidates for stack variables. However, Exceptions are typically thrown from a method to a caller (or its caller etc.) so its wouldn't be very useful placing the Exception on the stack.

提交回复
热议问题