dao icon indicating copy to clipboard operation
dao copied to clipboard

'switch type', exceptions and tragedy

Open Night-walker opened this issue 10 years ago • 9 comments

(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.

Night-walker avatar Aug 02 '15 09:08 Night-walker

It compiles, but fails at runtime with Get undefined field: line in case std.try() returned an error.

Night-walker avatar Aug 02 '15 10:08 Night-walker

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:.

Night-walker avatar Aug 02 '15 10:08 Night-walker

And switch (invar e = (Error)err) type gives Types not matching --- " 'invar<Err>' for 'none' " :scream:.

Night-walker avatar Aug 02 '15 10:08 Night-walker

#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.

Night-walker avatar Aug 02 '15 10:08 Night-walker

And I'd welcome the addition of Exception::.line().

Night-walker avatar Aug 02 '15 10:08 Night-walker

 #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.

daokoder avatar Aug 02 '15 13:08 daokoder

These methods are now commented out.

daokoder avatar Aug 03 '15 07:08 daokoder

BTW, there is currently no way to tell where the error was raised during testing, as Exception object doesn't provide such information.

Night-walker avatar Aug 05 '15 11:08 Night-walker

And I'd welcome the addition of Exception::.line().

Added.

daokoder avatar Aug 06 '15 15:08 daokoder