V Forum

[ log in ]

Any idea on Exception Handler?

templarzq 2019-06-11 08:00
havent found any error and exception handle method in docs。Any idea?
medvednikov 2019-06-11 11:55
Errors are handled with option types:


There's no way to catch panics (exceptions), but there will be a way to recover, just like in Go.
medvednikov 2019-06-11 11:56
There's no way to catch panics *yet*.
ansarizafar 2019-06-18 08:30
There should be a way to catch panics (exceptions), for remote logging and cleanup.
ntrel 2019-06-18 16:55
I'm concerned that being able to recover from a panic and continue running the program will both add complexity to the compiler as well as encourage using panics as exceptions - isn't panic/recover essentially just throw/catch? If V supports something like `defer` or better, struct destructors (so we can manage memory automatically) then panics will make code generation (and feature design) more complex.

For logging a panic or showing a dialog to the user, all that's needed is a callback function. Only being able to register a callback that is called on panic might make the compiler's job easier in the case of code that needs to run on scope exit.
medvednikov 2019-06-18 22:25
That's a very good point, @ntrel.

recover() is often overused in Go.

There will be `defer` by the way.

Powered by Vorum, open-source blogging/forum software written in V