Skip to content

Commit

Permalink
Try docs on vraptor-site
Browse files Browse the repository at this point in the history
  • Loading branch information
csokol committed Dec 29, 2014
1 parent 59d03b5 commit 9503b57
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions vraptor-site/content/en/docs/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,20 @@
~~~

Thus, when the data of an object are not present in the request, you will receive a `null` parameter instead of an empty instance.

## Using the Try class

You can use the class `Try` from the public API of VRaptor to handle exceptions more easily.

With this class, you can specify the code that might throw exceptions with the `run` method:

~~~
Try try = Try.run(() -> aDangerousMethod());
if (try.failed()) {
Exception e = try.getException();
handleError(e);
}
handleResult(try.result());
~~~

This class is really useful to compose several computations that can throw exceptions.
17 changes: 17 additions & 0 deletions vraptor-site/content/pt/docs/componentes.html
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,20 @@
~~~

Dessa forma, quando os dados de um objeto não estiverem presentes no request, você receberá um parâmetro `null` no lugar de uma instância vazia.

## Usando a classe Try

Para facilitar o tratamento de exceções, você pode usar a classe `Try`, da API pública do VRaptor.

Com essa classe, você pode especificar a código que pode lançar exceptions dentro do método `run`:

~~~
Try try = Try.run(() -> umMetodoPerigoso());
if (try.failed()) {
Exception e = try.getException();
lidaComErro(e);
}
lidaComResultado(try.result());
~~~

Essa classe é especialmente útil para compor diferentes trechos de código que lançam exceptions.

0 comments on commit 9503b57

Please sign in to comment.