Java Exception vs C++ Exceptions

后端 未结 6 1339
一向
一向 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 01:55

    Where are exceptions stored ? Stack, Heap. How is memory allocated and deallocated for Exceptions?

    Exceptions are objects like any other in this regard. Allocated on the heap via new, deallocated by the garbage collector.

    Now if you have more than one exception which needs to be handled are there objects of all these exceptions created?

    Not sure what you mean with this. They're created via new, one at a time. There can be more than one around when you use exception chaining - and there's actually nothing keeping you from creating thousands of exceptions and putting them in a List somewhere - it just doesn't make much sense.

提交回复
热议问题