Improve failwith description.

This commit is contained in:
Sander Spies 2020-06-08 11:58:23 +02:00
parent 5cfe6e893c
commit d99d1bbe66
2 changed files with 46 additions and 46 deletions

View File

@ -598,53 +598,17 @@ let main = (p : unit) : address => Tezos.source;
<SyntaxTitle syntax="pascaligo"> <SyntaxTitle syntax="pascaligo">
function failwith : string -> unit function failwith : 'a -> unit
</SyntaxTitle> </SyntaxTitle>
<SyntaxTitle syntax="cameligo"> <SyntaxTitle syntax="cameligo">
function failwith : string -> unit function failwith : 'a -> unit
</SyntaxTitle> </SyntaxTitle>
<SyntaxTitle syntax="reasonligo"> <SyntaxTitle syntax="reasonligo">
function failwith : string -> unit function failwith: 'a -> unit
</SyntaxTitle> </SyntaxTitle>
Cause the contract to fail with an error message. [See `failwith`](toplevel.md#failwith)
> ⚠ Using this currently requires in general a type annotation on the
> `failwith` call.
<Syntax syntax="cameligo">
Note that `Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
<Syntax syntax="reasonligo">
Note that `Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
<Syntax syntax="pascaligo">
```pascaligo
function main (const p : int; const s : unit) : list (operation) * unit is
block {
if p > 10 then failwith ("Failure.") else skip
}
with ((nil : list (operation)), s)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let main (p,s : int * unit) = if p > 10 then failwith "Failure."
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let main = ((p,s) : (int, unit)) =>
if (p > 10) { failwith ("Failure."); };
```
</Syntax>
<SyntaxTitle syntax="pascaligo"> <SyntaxTitle syntax="pascaligo">
function chain_id : chain_id function chain_id : chain_id

View File

@ -60,20 +60,56 @@ let (): unit
A helper to create a unit. A helper to create a unit.
<a name="failwith"></a>
<SyntaxTitle syntax="pascaligo"> <SyntaxTitle syntax="pascaligo">
function failwith : string -> unit function failwith : 'a -> unit
</SyntaxTitle> </SyntaxTitle>
<SyntaxTitle syntax="cameligo"> <SyntaxTitle syntax="cameligo">
val failwith : string -> unit val failwith : 'a -> unit
</SyntaxTitle> </SyntaxTitle>
<SyntaxTitle syntax="reasonligo"> <SyntaxTitle syntax="reasonligo">
let failwith: string => unit let failwith: 'a => unit
</SyntaxTitle> </SyntaxTitle>
Cause the contract to fail with an error message. Cause the contract to fail with an error message or integer. Other types are
not supported at the moment.
Using this currently requires in general a type annotation on the
`failwith` call.
<Syntax syntax="pascaligo">
```pascaligo
function main (const p : int; const s : unit) : list (operation) * unit is
block {
if p > 10 then failwith ("Failure.") else skip
}
with ((nil : list (operation)), s)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let main (p,s : int * unit) = if p > 10 then failwith "Failure."
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let main = ((p,s) : (int, unit)) =>
if (p > 10) { failwith ("Failure."); };
```
</Syntax>
<Syntax syntax="cameligo">
`Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
<Syntax syntax="reasonligo">
`Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
> ⚠ Using this currently requires in general a type annotation on the
> `failwith` call.
<SyntaxTitle syntax="pascaligo"> <SyntaxTitle syntax="pascaligo">
function assert : bool -> unit function assert : bool -> unit