| Index: runtime/vm/exceptions.cc
|
| diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc
|
| index 6d27fe1f33a2840424d29f33ecc9c764aa292ac4..f927af1c47f55381174a1ac46bd90eebaec0440c 100644
|
| --- a/runtime/vm/exceptions.cc
|
| +++ b/runtime/vm/exceptions.cc
|
| @@ -412,45 +412,47 @@ static void ThrowExceptionHelper(Isolate* isolate,
|
| &handler_sp,
|
| &handler_fp,
|
| &handler_needs_stacktrace);
|
| - Array& code_array = Array::Handle(isolate, Object::empty_array().raw());
|
| - Array& pc_offset_array =
|
| - Array::Handle(isolate, Object::empty_array().raw());
|
| - // If we have an error with a stacktrace field then collect the full stack
|
| - // trace and store it into the field.
|
| - if (!stacktrace_field.IsNull()) {
|
| - if (exception.GetField(stacktrace_field) == Object::null()) {
|
| - // This is an error object and we need to capture the full stack trace
|
| - // here implicitly, so we set up the stack trace. The stack trace
|
| - // field is set only once, it is not overriden.
|
| - const Stacktrace& full_stacktrace =
|
| - Stacktrace::Handle(isolate, Exceptions::CurrentStacktrace());
|
| - exception.SetField(stacktrace_field, full_stacktrace);
|
| + if (!stacktrace_field.IsNull() || handler_needs_stacktrace) {
|
| + Array& code_array = Array::Handle(isolate, Object::empty_array().raw());
|
| + Array& pc_offset_array =
|
| + Array::Handle(isolate, Object::empty_array().raw());
|
| + // If we have an error with a stacktrace field then collect the full stack
|
| + // trace and store it into the field.
|
| + if (!stacktrace_field.IsNull()) {
|
| + if (exception.GetField(stacktrace_field) == Object::null()) {
|
| + // This is an error object and we need to capture the full stack trace
|
| + // here implicitly, so we set up the stack trace. The stack trace
|
| + // field is set only once, it is not overriden.
|
| + const Stacktrace& full_stacktrace =
|
| + Stacktrace::Handle(isolate, Exceptions::CurrentStacktrace());
|
| + exception.SetField(stacktrace_field, full_stacktrace);
|
| + }
|
| }
|
| - }
|
| - if (handler_needs_stacktrace) {
|
| - RegularStacktraceBuilder frame_builder(false);
|
| - BuildStackTrace(isolate, &frame_builder);
|
| + if (handler_needs_stacktrace) {
|
| + RegularStacktraceBuilder frame_builder(false);
|
| + BuildStackTrace(isolate, &frame_builder);
|
|
|
| - // Create arrays for code and pc_offset tuples of each frame.
|
| - code_array = Array::MakeArray(frame_builder.code_list());
|
| - pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list());
|
| - }
|
| - if (existing_stacktrace.IsNull()) {
|
| - stacktrace = Stacktrace::New(code_array, pc_offset_array);
|
| - } else {
|
| - ASSERT(is_rethrow);
|
| - stacktrace ^= existing_stacktrace.raw();
|
| - if (pc_offset_array.Length() != 0) {
|
| - // Skip the first frame during a rethrow. This is the catch clause with
|
| - // the rethrow statement, which is not part of the original trace a
|
| - // rethrow is supposed to preserve.
|
| - stacktrace.Append(code_array, pc_offset_array, 1);
|
| + // Create arrays for code and pc_offset tuples of each frame.
|
| + code_array = Array::MakeArray(frame_builder.code_list());
|
| + pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list());
|
| + }
|
| + if (existing_stacktrace.IsNull()) {
|
| + stacktrace = Stacktrace::New(code_array, pc_offset_array);
|
| + } else {
|
| + ASSERT(is_rethrow);
|
| + stacktrace ^= existing_stacktrace.raw();
|
| + if (pc_offset_array.Length() != 0) {
|
| + // Skip the first frame during a rethrow. This is the catch clause
|
| + // with the rethrow statement, which is not part of the original
|
| + // trace a rethrow is supposed to preserve.
|
| + stacktrace.Append(code_array, pc_offset_array, 1);
|
| + }
|
| + // Since we are re throwing and appending to the existing stack trace
|
| + // we clear out the catch trace collected in the existing stack trace
|
| + // as that trace will not be valid anymore.
|
| + stacktrace.SetCatchStacktrace(Object::empty_array(),
|
| + Object::empty_array());
|
| }
|
| - // Since we are re throwing and appending to the existing stack trace
|
| - // we clear out the catch trace collected in the existing stack trace
|
| - // as that trace will not be valid anymore.
|
| - stacktrace.SetCatchStacktrace(Object::empty_array(),
|
| - Object::empty_array());
|
| }
|
| }
|
| // We expect to find a handler_pc, if the exception is unhandled
|
|
|