Skip to content

Instantly share code, notes, and snippets.

@nulld

nulld/Main.hx Secret

Last active July 6, 2018 10:22
Show Gist options
  • Save nulld/71175b3b24fa56dcdb8d9fa169caa9f6 to your computer and use it in GitHub Desktop.
Save nulld/71175b3b24fa56dcdb8d9fa169caa9f6 to your computer and use it in GitHub Desktop.
Why not catched?
-cpp out
-cp .
-debug
-main Main
package;
interface ISomeInterface
{
function getSomeProperty():Float;
}
class SomeClass {
var nullPointer:ISomeInterface;
public var someProperty(get, null):Float;
public function new() {}
function get_someProperty():Float {
return nullPointer.getSomeProperty();
}
}
class Main
{
public static function main(): Void
{
var inst = new SomeClass();
trace("Begin");
trace("Begin case 1");
try {
var unexistProperty = Reflect.getProperty(inst, "unexistProperty");
trace(unexistProperty.some);
}
catch(e:Dynamic) {
trace(e); //Null Object Reference - works as expected
}
trace("End case 1");
trace("Begin case 2");
try {
var val = Reflect.getProperty(inst, "someProperty"); //Just crash
trace(val);
}
catch(e:Any) {
trace(e);
}
trace("End case 2");
trace("Finish");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment