Skip to content

Instantly share code, notes, and snippets.

@lptr
Last active December 24, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lptr/6883642 to your computer and use it in GitHub Desktop.
Save lptr/6883642 to your computer and use it in GitHub Desktop.
~/Temp/001$ haxe -js test2.js -main Test2 Test2.hx && node test2.js
/Users/lptr/Temp/001/test2.js:22
if(value == null) throw new TiborError("" + name + " must not be null");
^
Error: Tibor: tibor must not be null
at new CustomError (/Users/lptr/Temp/001/test2.js:9:14)
at TiborError (/Users/lptr/Temp/001/test2.js:14:14)
at Function.Test2.checkNotNull (/Users/lptr/Temp/001/test2.js:22:26)
at Function.Test2.main (/Users/lptr/Temp/001/test2.js:27:8)
at /Users/lptr/Temp/001/test2.js:29:7
at Object.<anonymous> (/Users/lptr/Temp/001/test2.js:30:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
import Type;
#if js
@:native("Error")
extern class Error
{
var message : String;
var name : String;
var stack(default,null) : String;
function new(?message : String) : Void;
}
#elseif flash
import flash.errors.Error;
#end
class CustomError
#if !js
extends Error
#end
{
public function new(?message:String)
{
#if js
var proto = untyped __js__("new Error()");
proto.message = message;
untyped __js__("this.constructor.prototype.__proto__ = proto");
#else
super(message);
#end
}
}
class TiborError extends CustomError {
public function new(message:String)
{
super("Tibor: " + message);
}
}
class Test2 {
public static function checkNotNull<T>(value:T, name:String = "a parameter"):T
{
if (value == null)
{
throw new TiborError('$name must not be null');
}
return value;
}
public static function main()
{
checkNotNull("Lajos", "lajos");
checkNotNull(null, "tibor");
}
}
(function () { "use strict";
function $extend(from, fields) {
function inherit() {}; inherit.prototype = from; var proto = new inherit();
for (var name in fields) proto[name] = fields[name];
if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString;
return proto;
}
var CustomError = function(message) {
var proto = new Error();
proto.message = message;
this.constructor.prototype.__proto__ = proto;
};
var TiborError = function(message) {
CustomError.call(this,"Tibor: " + message);
};
TiborError.__super__ = CustomError;
TiborError.prototype = $extend(CustomError.prototype,{
});
var Test2 = function() { }
Test2.checkNotNull = function(value,name) {
if(name == null) name = "a parameter";
if(value == null) throw new TiborError("" + name + " must not be null");
return value;
}
Test2.main = function() {
Test2.checkNotNull("Lajos","lajos");
Test2.checkNotNull(null,"tibor");
}
Test2.main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment