execute with error handling
| 52 | |
| 53 | // execute with error handling |
| 54 | value statement::execute(context & ctx) { |
| 55 | try { |
| 56 | return execute_impl(ctx); |
| 57 | } catch (const continue_statement::signal & /* ex */) { |
| 58 | throw; |
| 59 | } catch (const break_statement::signal & /* ex */) { |
| 60 | throw; |
| 61 | } catch (const rethrown_exception & /* ex */) { |
| 62 | throw; |
| 63 | } catch (const not_implemented_exception & /* ex */) { |
| 64 | throw; |
| 65 | } catch (const std::exception & e) { |
| 66 | const std::string & source = *ctx.src; |
| 67 | if (source.empty()) { |
| 68 | std::ostringstream oss; |
| 69 | oss << "\nError executing " << type() << " at position " << pos << ": " << e.what(); |
| 70 | throw rethrown_exception(oss.str()); |
| 71 | } else { |
| 72 | std::ostringstream oss; |
| 73 | oss << "\n------------\n"; |
| 74 | oss << "While executing " << type() << " at " << get_line_col(source, pos) << " in source:\n"; |
| 75 | oss << peak_source(source, pos) << "\n"; |
| 76 | oss << "Error: " << e.what(); |
| 77 | // throw as another exception to avoid repeated formatting |
| 78 | throw rethrown_exception(oss.str()); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | value identifier::execute_impl(context & ctx) { |
| 84 | auto it = ctx.get_val(val); |