ValueException.hx 897 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package haxe;
  2. /**
  3. An exception containing arbitrary value.
  4. This class is automatically used for throwing values, which don't extend `haxe.Exception`
  5. or native exception type.
  6. For example:
  7. ```haxe
  8. throw "Terrible error";
  9. ```
  10. will be compiled to
  11. ```haxe
  12. throw new ValueException("Terrible error");
  13. ```
  14. **/
  15. class ValueException extends Exception {
  16. /**
  17. Thrown value.
  18. **/
  19. public var value(default,null):Any;
  20. public function new(value:Any, ?previous:Exception, ?native:Any):Void {
  21. super(#if js js.Syntax.code('String({0})', value) #else Std.string(value) #end, previous, native);
  22. this.value = value;
  23. }
  24. /**
  25. Extract an originally thrown value.
  26. This method must return the same value on subsequent calls.
  27. Used internally for catching non-native exceptions.
  28. Do _not_ override unless you know what you are doing.
  29. **/
  30. override function unwrap():Any {
  31. return value;
  32. }
  33. }