Exceptions.hx 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package java.internal;
  2. import java.lang.Throwable;
  3. @:nativegen @:keep @:native("haxe.lang.HaxeException") private class HaxeException extends RuntimeException
  4. {
  5. private var obj:Dynamic;
  6. public function new(obj:Dynamic, msg:String, cause:Throwable)
  7. {
  8. super(msg, cause);
  9. if (Std.is(obj, HaxeException))
  10. {
  11. var _obj:HaxeException = cast obj;
  12. obj = _obj.getObject();
  13. }
  14. this.obj = obj;
  15. }
  16. public function getObject():Dynamic
  17. {
  18. return obj;
  19. }
  20. public function toString():String
  21. {
  22. return "Haxe Exception: " + obj;
  23. }
  24. public static function wrap(obj:Dynamic):RuntimeException
  25. {
  26. if (Std.is(obj, RuntimeException))
  27. return obj;
  28. if (Std.is(obj, String))
  29. return new HaxeException(obj, obj, null);
  30. else if (Std.is(obj, Throwable))
  31. return new HaxeException(obj, null, obj);
  32. return new HaxeException(obj, null, null);
  33. }
  34. }