
Return stacktrace exception type
LadyCailinBot opened this issue ยท 3 comments
CMDHELPER-2662 - Reported by Tom.Gebbett
I'd like to be able to use my own system to deal with exceptions, and i'm sure there are many other great uses for this.
i'd also like try(code,@exc,code) to set @exc to a stacktrace exception rather than the older single-location exception type.
Ideally, we could use stacktrace() to return an array of relevant data. I would mainly use this to return the current location in code, mostly for debugging purposes, but i would also probably integrate a new system of error reporting that could give more information and change program flow based on elements of the stacktrace. It would be good to be able to call the function without any exception occuring, which would just set some indices in the array returned to null.
array(exception:'ExceptionType',detail:'Exception Detail',stack:array(array(function:'function',procedure:'_proc',line:0,col:0,file:'/folder/file.ms'),[...]))
I may have missed some stuff from there, but i hope you get the idea.
There are likely some pieces of information that could be passed as parameters to the function, but i don't think that that would be necessary.
Not sure if there's a good reason that the newer stacktrace exception type isn't used more, if so i'd like to know anyway :)
I also have no idea how much work this would involve, and it is understandable that this would be a low priority addition.
Comment by LadyCailin
Actually, once I get the new compiler done, I was going to add a more modern try/catch*/finally? mechanism, like java and other languages have. This would include full stacktrace information like the existing output has, and allow for more standard brace syntax. As you can tell, I did update the error handling a while back to provide an actual stack trace, so getting that stacktrace to you as part of the try catch system will not be hard. However, it builds off of java's stacktrace mechanism, so being able to simply do stacktrace() won't be as easy, because it requires actually throwing an exception in order to build it up, which obviously isn't what we want to do if we intend on continuing with our code as normal. In general, I think that languages usually have to provide very low level support for doing something like that, because it tends to be very inefficient to carry around the stacktrace data during normal runtime, if you're never going to end up using it. Also, exposing that tends to end up causing more abuse than legitimate uses.
Having said all that, definitely going to add the first bit, we'll see about adding stacktrace() after that.
Comment by Tom.Gebbett
Yes, i realised that if i could get the new stack trace type with try, that i could just use try(throw(),@exc,'') and then parse @exc. That would suffice for the stacktrace() function, and i understand what you said about it being generated on a lower level than your system, that's totally reasonable.
Thanks for the reply and i look forward to the coming additions :)