Wiki source code of ThrowError
Last modified by Outhman Moustaghfir on 2025/03/21 11:29
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | == **Description** == | ||
2 | |||
3 | The ThrowError function is used to generate custom error messages in XSLT transformations. When triggered, it stops the execution and displays the error message provided by the user. | ||
4 | |||
5 | == **Syntax** == | ||
6 | |||
7 | {{{ | ||
8 | }}} | ||
9 | |||
10 | {{code language="XML"}} | ||
11 | <TEST><xsl:value-of select="ixf:ThrowError('Error message format', value1, value2, ...)"/></TEST> | ||
12 | |||
13 | {{/code}} | ||
14 | |||
15 | * 'Error message format': A string that represents the error message. It can include placeholders ~(%1, %2, etc.) to insert variable values. | ||
16 | * value1, value2, ...: The values that replace the placeholders in the message. | ||
17 | |||
18 | == **Example Usages** == | ||
19 | |||
20 | === **1. Simple Error Message** === | ||
21 | |||
22 | This example throws a general error message: | ||
23 | |||
24 | {{code language="XML"}} | ||
25 | <TEST><xsl:value-of select="ixf:ThrowError('An unexpected error occurred. Please try again.')"/></TEST> | ||
26 | {{/code}} | ||
27 | |||
28 | |||
29 | 💡 **Output:** | ||
30 | |||
31 | {{code language="vbnet"}} | ||
32 | An unexpected error occurred. Please try again. | ||
33 | {{/code}} | ||
34 | |||
35 | |||
36 | === **2. Error with Dynamic Values** === | ||
37 | |||
38 | If an error message requires dynamic values, placeholders ~(%1, %2, etc.) can be used: | ||
39 | |||
40 | {{code language="XML"}} | ||
41 | <TEST><xsl:value-of select="ixf:ThrowError('Invalid input: %1. Expected: %2.', 'abc', 'number')"/></TEST> | ||
42 | {{/code}} | ||
43 | |||
44 | |||
45 | 💡 **Output:** | ||
46 | |||
47 | {{code language="XML"}} | ||
48 | Invalid input: abc. Expected: number. | ||
49 | {{/code}} | ||
50 | |||
51 | |||
52 | === **3. Missing Required Field** === | ||
53 | |||
54 | {{{ | ||
55 | }}} | ||
56 | |||
57 | {{code language="XML"}} | ||
58 | <TEST><xsl:value-of select="ixf:ThrowError('Missing required field: %1.', 'Username')"/></TEST> | ||
59 | {{/code}} | ||
60 | |||
61 | |||
62 | 💡 **Output:** | ||
63 | |||
64 | {{code language="XML"}} | ||
65 | Missing required field: Username. | ||
66 | {{/code}} | ||
67 | |||
68 | |||
69 | === **4. Access Denied Error** === | ||
70 | |||
71 | |||
72 | 💡 **Output:** | ||
73 | |||
74 | {{code language="XML"}} | ||
75 | Access denied. User JohnDoe does not have permission. | ||
76 | {{/code}} | ||
77 | |||
78 | |||
79 | === **5. Operation Failure** === | ||
80 | |||
81 | |||
82 | 💡 **Output:** | ||
83 | |||
84 | {{code language="XML"}} | ||
85 | Operation failed. Error: Database connection lost. | ||
86 | {{/code}} | ||
87 | |||
88 |