Reputation: 55
I'd like to share an issue that the function Exception(Message [, What, Extra])
doesn't work as expected if the script is compiled in .exe
Exception("").What
give the current method/function/subroutine if the script is not compiled
Exception("", -2).What
give the parent method where the method/function/subroutine has been called if the script is not compiled
Excetpion("").What
give the current method/function/subroutine if the script is compiled .exe
Exception("", -2).What
give only -2 if the script is compiled .exe
class MyClass { Method1() { MsgBox % MyClass.Method2() } Method2() { return Exception("", -2).What } } MyClass.Method1()
In non compiled MyClass.Method1()
display MyClass.Method1
But in compiled .exe script MyClass.Method1()
display -2
Anyone has a solution to display the method instead the number if the script is compiled?
Upvotes: 0
Views: 43
Reputation: 6489
It actually does work as expected, as this behavior is stated in the documentation:
If What is omitted, it defaults to the name of the current function or subroutine. Otherwise it can be a string or a negative offset from the top of the call stack. For example, a value of -1 sets
Exception.What
to the current function or subroutine, andException.Line
andException.File
to the line and file which called it. However, if the script is compiled or the offset is invalid, What is simply converted to a string.
Also, I think your implementation here is a bit weird, surely you'd want to throw exceptions instead of returning them?
Anyway, I guess your solution would be to somehow implement this yourself.
You could for example pass the caller in as an argument:
instance := new MyClass
try
instance.Method1()
catch e
MsgBox, % e.What
class MyClass
{
Method1()
{
this.Method2(A_ThisFunc)
}
Method2(caller)
{
throw Exception("", caller)
}
}
Upvotes: 1