From 43ac1b6e04ca40b63b6806c96747be675992e2a3 Mon Sep 17 00:00:00 2001 From: Sekulum Forka Date: Thu, 13 May 2021 15:26:14 +0200 Subject: [PATCH] Exceptions: Refactoring exception making code --- src/fsh.nim | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/fsh.nim b/src/fsh.nim index 624ed69..9b90010 100644 --- a/src/fsh.nim +++ b/src/fsh.nim @@ -31,11 +31,35 @@ type line: int col: int whileExec: string - ShellVariableError=object of ShellError + ShellVariableError= object of ShellError variable: string ShellCommandError = object of ShellError command: string +# procs for making procedures +proc newShellException(msg: string, line=0, col=0, whileExec=""): ref ShellError = + var e = newException(ShellError, msg) + e.line=line + e.col=col + e.whileExec = whileExec + return e + +proc newShellVariableException(msg: string, vari: string, line=0, col=0, whileExec=""): ref ShellVariableError = + var e= newException(ShellVariableError, msg) + e.variable =vari + e.line=line + e.col=col + e.whileExec=whileExec + return e + +proc newShellCommandException(msg: string, command: string, line=0, col=0, whileExec=""): ref ShellCommandError = + var e=newException(ShellCommandError, msg) + e.command=command + e.line=line + e.col=col + e.whileExec=whileExec + return e + # forward declarations proc eval(cmd: string): string proc substitute(strm: Stream, delim = ";\p"): string