Explorar el Código

changed Exception.toString() to return message only (closes #9341)
added Exception.details()

Aleksandr Kuzmenko hace 5 años
padre
commit
4e3fe7a875

+ 7 - 11
src/macro/eval/evalExceptions.ml

@@ -95,18 +95,14 @@ let uncaught_exception_string v p extra =
 	(Printf.sprintf "%s : Uncaught exception %s%s" (format_pos p) (value_string v) extra)
 
 let get_exc_error_message ctx v stack p =
-	if is v key_haxe_Exception then
+	let pl = List.map (fun env -> {pfile = rev_hash env.env_info.pfile;pmin = env.env_leave_pmin; pmax = env.env_leave_pmax}) stack in
+	let pl = List.filter (fun p -> p <> null_pos) pl in
+	match pl with
+	| [] ->
 		uncaught_exception_string v p ""
-	else begin
-		let pl = List.map (fun env -> {pfile = rev_hash env.env_info.pfile;pmin = env.env_leave_pmin; pmax = env.env_leave_pmax}) stack in
-		let pl = List.filter (fun p -> p <> null_pos) pl in
-		match pl with
-		| [] ->
-			uncaught_exception_string v p ""
-		| _ ->
-			let sstack = String.concat "\n" (List.map (fun p -> Printf.sprintf "%s : Called from here" (format_pos p)) pl) in
-			Printf.sprintf "%sUncaught exception %s\n%s" (if p = null_pos then "" else format_pos p ^ " : ") (value_string v) sstack
-	end
+	| _ ->
+		let sstack = String.concat "\n" (List.map (fun p -> Printf.sprintf "%s : Called from here" (format_pos p)) pl) in
+		Printf.sprintf "%sUncaught exception %s\n%s" (if p = null_pos then "" else format_pos p ^ " : ") (value_string v) sstack
 
 let build_exception_stack ctx env =
 	let eval = env.env_eval in

+ 0 - 1
src/macro/eval/evalHash.ml

@@ -82,7 +82,6 @@ let key_haxe_macro_Unsafe = hash "haxe.macro.Unsafe"
 let key_sys_io__Process_NativeProcess = hash "sys.io._Process.NativeProcess"
 let key_sys_io_FileOutput = hash "sys.io.FileOutput"
 let key_sys_io_FileInput = hash "sys.io.FileInput"
-let key_haxe_Exception = hash "haxe.Exception"
 let key_haxe_io_Eof = hash "haxe.io.Eof"
 let key_haxe_macro_ExprDef = hash "haxe.macro.ExprDef"
 let key_haxe_macro_Binop = hash "haxe.macro.Binop"

+ 4 - 0
std/cpp/_std/haxe/Exception.hx

@@ -50,6 +50,10 @@ class Exception {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/cs/_std/haxe/Exception.hx

@@ -64,6 +64,10 @@ class Exception extends NativeException {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/eval/_std/haxe/Exception.hx

@@ -50,6 +50,10 @@ class Exception {
 
 	@:ifFeature("haxe.Exception.thrown")
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/flash/_std/haxe/Exception.hx

@@ -54,6 +54,10 @@ class Exception extends NativeException {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 8 - 3
std/haxe/Exception.hx

@@ -96,12 +96,17 @@ extern class Exception {
 	private function unwrap():Any;
 
 	/**
-		Exception description.
-
-		Includes message, stack and the previous exception (if set).
+		Returns exception message.
 	**/
 	public function toString():String;
 
+	/**
+		Detailed exception description.
+
+		Includes message, stack and the chain of previous exceptions (if set).
+	**/
+	public function details():String;
+
 	/**
 		If this field is defined in a target implementation, then a call to this
 		field will be generated automatically in every constructor of derived classes

+ 4 - 0
std/hl/_std/haxe/Exception.hx

@@ -49,6 +49,10 @@ class Exception {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/java/_std/haxe/Exception.hx

@@ -62,6 +62,10 @@ class Exception extends NativeException {
 	}
 
 	override public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/js/_std/haxe/Exception.hx

@@ -72,6 +72,10 @@ class Exception extends NativeException {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/lua/_std/haxe/Exception.hx

@@ -50,6 +50,10 @@ class Exception {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/neko/_std/haxe/Exception.hx

@@ -50,6 +50,10 @@ class Exception {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/php/_std/haxe/Exception.hx

@@ -53,6 +53,10 @@ class Exception extends NativeException {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 4 - 0
std/python/_std/haxe/Exception.hx

@@ -59,6 +59,10 @@ class Exception extends PyException {
 	}
 
 	public function toString():String {
+		return message;
+	}
+
+	public function details():String {
 		return inline CallStack.exceptionToString(this);
 	}
 

+ 3 - 4
tests/misc/projects/Issue9286/compile-fail.hxml.stderr

@@ -1,4 +1,3 @@
-Main.hx:7: characters 3-8 : Uncaught exception Exception: !
-Called from Main.level3 (Main.hx line 7 column 3)
-Called from Main.level2 (Main.hx line 3 column 3)
-Called from Main.main (Main.hx line 11 column 3)
+Main.hx:7: characters 3-8 : Uncaught exception !
+Main.hx:3: characters 3-11 : Called from here
+Main.hx:11: characters 3-11 : Called from here