Actually it has already been done in some cases. Try this, for instance:
Pike v7.4 release 29 running Hilfe v3.5 (Incremental Pike Frontend)
mixed err = catch (cpp ("#ifdef"));
-:1:#ifdef what? -:1:End of file while searching for #endif.
objectp (err);
(1) Result: 1
err;
(2) Result: cpp_error("Cpp() failed\n")
indices (err);
(3) Result: ({ /* 10 elements */ "is_cpp_error", "backtrace", "describe", "__backtrace", "__desc", "error_type", "_sprintf", "`[]", "cast", "is_generic_error" })
err->error_type;
(4) Result: "cpp_error"
err->backtrace();
(5) Result: ({ /* 9 elements */ backtrace_frame(/home/mast/Pike/frozen/build/linux-2.4.20-i686/master.pike:1911, _main(), Args: 2), backtrace_frame(Unknown file, StdinHilfe(), No args), backtrace_frame(/home/mast/Pike/frozen/lib/modules/Tools.pmod/Hilfe.pmod:2043, create(), No args), backtrace_frame(/home/mast/Pike/frozen/lib/modules/Tools.pmod/Hilfe.pmod:1270, add_input_line(), Args: 1), backtrace_frame(/home/mast/Pike/frozen/lib/modules/Tools.pmod/Hilfe.pmod:1319, add_buffer(), Args: 1), backtrace_frame(/home/mast/Pike/frozen/lib/modules/Tools.pmod/Hilfe.pmod:1681, parse_expression(), Args: 1), backtrace_frame(/home/mast/Pike/frozen/lib/modules/Tools.pmod/Hilfe.pmod:1368, add_hilfe_variable(), Args: 3), backtrace_frame(/home/mast/Pike/frozen/lib/modules/Tools.pmod/Hilfe.pmod:1890, hilfe_compile(), Args: 2), backtrace_frame(HilfeInput:1, __INIT(), No args) })
err->is_cpp_error;
(6) Result: 1
err->is_generic_error;
(7) Result: 1
/ Martin Stjernholm, Roxen IS
Previous text:
2003-10-01 18:50: Subject: Re: throw or return
You are absolutely right. The exception objects are an orthogonal issue to how to trap them. On the whole I think your suggestion looks fairly good. The compatibility implications of changing the current ({ "error", backtrace() }) de facto standard into an object based one is probably acceptable.
/ Martin Nilsson (saturator)