Skip to content

Commit 62edde3

Browse files
author
aafent
committed
ERROR statement in Events Library
1 parent b62ca70 commit 62edde3

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

FAST.FBasic.InteractiveConsole/Tests/test.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ retrieve Cust, APPEND, *, "select CustomerID, Name, Email,City from Customers wh
55
retrieve Cust, APPEND, 1, "select CustomerID, Name, Email,City from Customers"
66
retrieve Cust, APPEND, 2, "select CustomerID, Name, Email,City from Customers"
77

8+
Error 1,"Not found"
9+
810
print "Count="+ubound("Cust")
911
print [Cust.CustomerID]+": Name:"+[Cust.Name]+", Email: "+[Cust.Email]
1012

FAST.FBasic.LibraryToolkit/Core/Errors.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
{
33
public static class Errors
44
{
5+
public static string E001_UserError(string msg)
6+
{
7+
return $"{msg} [E001].";
8+
}
59

610
public static string E100_RequestForObjectHandlerNotInstalled(IFBasicRequestForObjectDescriptor request =null, string more="")
711
{

FAST.FBasicInterpreter/Libraries/FBasicEvents.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Statements:
66
77
RAISEEVENT event_name [, parameter1, parameter2, ...] Triggers an event named event_name and optionally passes data (parameters) to any registered handlers.
8+
ERROR RESULTVALUE, error_message
89
*/
910
public class FBasicEvents : IFBasicLibrary
1011
{
@@ -17,6 +18,7 @@ public class FBasicEvents : IFBasicLibrary
1718
public void InstallAll(IInterpreter interpreter)
1819
{
1920
interpreter.AddStatement("RAISEEVENT", RaiseEvent);
21+
interpreter.AddStatement("ERROR", RaiseError);
2022
}
2123

2224

@@ -80,6 +82,22 @@ private static void RaiseEvent(IInterpreter interpreter)
8082

8183
}
8284

85+
private static void RaiseError(IInterpreter interpreter)
86+
{
87+
//Syntax: Error RESULTVALUE, error_message
88+
interpreter.SetVar("RESULTVALUE",interpreter.ValueOrVariable(true));
89+
90+
interpreter.GetNextToken();
91+
interpreter.MatchAndThenNextToken(Token.Comma);
92+
93+
var msg= interpreter.ValueOrVariable(true).ToString();
94+
95+
interpreter.Error($"",Errors.E001_UserError(msg));
96+
return;
97+
98+
}
99+
100+
83101
}
84102

85103
}

0 commit comments

Comments
 (0)