'switch type', exceptions and tragedy
(dao) const Err = Error::define('Some')
= none
(dao) switch (invar e = std.try{}) type {
..... case Err: io.writeln(err.line)
..... }
[[ERROR]] in file "interactive codes":
At line 0 : Invalid function definition --- " __main__() ";
At line 2 : Invalid virtual machine instruction --- " GETF:7,3,8 ";
In code snippet:
15 : GETVG : 0 , 2 , 7 ; 2; err
>> 16 : GETF : 7 , 3 , 8 ; 2; err. line
17 : MOVE : 8 , 0 , 11 ; 2; err. line
At line 2 : Member not exist --- " err. line for invar<list<Error>|Error|@T> "
;
It compiles fine if invar e = ... is moved outside the switch.
It compiles, but fails at runtime with Get undefined field: line in case std.try() returned an error.
Even switch ((Error)err) gives me the same error -- Member not exist --- " err. line for invar<list<Error>|Error|@T>, i.e. the type cast has no effect :astonished:.
And switch (invar e = (Error)err) type gives Types not matching --- " 'invar<Err>' for 'none' " :scream:.
#ifdef DEBUG
{ Dao_Exception_Getf, ".( self: Exception, name: string )=>any" },
{ Dao_Exception_Setf, ".=( self: Exception, name: string, value: any)" },
#endif
:sob:
An excellent way to shoot one's leg, no doubt. Please, remove this hack.
And I'd welcome the addition of Exception::.line().
#ifdef DEBUG { Dao_Exception_Getf, ".( self: Exception, name: string )=>any" }, { Dao_Exception_Setf, ".=( self: Exception, name: string, value: any)" }, #endif:sob:
An excellent way to shoot one's leg, no doubt. Please, remove this hack.
That wasn't a hack, it was added merely for testing when developing the relevant feature. I didn't expect it to be used. Of course, it should be removed.
These methods are now commented out.
BTW, there is currently no way to tell where the error was raised during testing, as Exception object doesn't provide such information.
And I'd welcome the addition of Exception::.line().
Added.