When an error occurs, it would be helpful for me to see the call stack, rather than just current line. I think I can make/register my own custom error handler using OnError. Does anyone have a good example from their own libraries of a handler that does this?
Is creating an Error handler the only way to modify the behavior? Is there a way to modify the Error object itself (or subclass it) in a way that causes the standard error dialog contents to include the stack?
How to display call stack by default? Topic is solved
Re: How to display call stack by default? Topic is solved
Code: Select all
#Requires AutoHotkey v2.0-beta.1
OnError(handler)
handler(Err, Mode) {
msg := 'Error: ' Err.Message '`n`n'
if (Err.Extra != '')
msg .= 'Specifically: ' Err.Extra '`n`n'
msg .= '`tLine#`n'
for line in StrSplit(Err.Stack, '`n')
{
; if can extract lineNr digits and source text?
if RegExMatch(line, '^\Q' A_ScriptFullPath '\E \((\d+)\) (:.*)$', &M)
{
lineNr := Format('{:05}', M[1]) ; zero left pad 5x
lineText := M[2] ; caller + src text
if (A_Index = 1)
msg .= '--->`t' lineNr lineText
else
msg .= '`t' lineNr lineText
}
else
msg .= '`t' line ; eg '> Auto-Execute' or other unexpected formats
msg .= '`n'
}
switch Mode
{
case 'Return':
msg .= 'Try to continue anyway?'
static MB_TOPMOST := 0x00040000, MB_DEFBUTTON2 := 0x00000100, MB_YESNO := 0x00000004
switch MsgBox(msg, , MB_TOPMOST | MB_DEFBUTTON2 | MB_YESNO)
{
case 'Yes': return -1
case 'No': return 0
}
case 'Exit': msg .= 'The current thread will exit.'
case 'ExitApp': msg .= 'The program is now unstable and will exit.'
}
MsgBox msg
}
maybe but wouldnt recommend, since u cant get by the character limitations
Re: How to display call stack by default?
@swagfag, perfect! Just what I was looking for. Thanks!
Who is online
Users browsing this forum: Pyper and 69 guests