Checked Exceptions

4 views
Skip to first unread message

Klaus Wuestefeld

unread,
Oct 25, 2007, 11:08:56 PM10/25/07
to boo...@googlegroups.com
> > N tem checked exceptions nas declaracoes do bytecode Java?
>
> São apenas anotações. A JVM não liga.

Quer dizer q vc pode gerar um código válido para a JVM q chama um
metodo q joga checked exception e n da nem catch nem declara throw?


> > N tem checked exceptions em boo?
>
> Não.

Com qual parte de "explicit is better than implicit" vc n concorda?

Falando sério agora, sei q as exceptions checadas enrigessem a
plasticidade do código. :(

Sabe o q seria massa? Uma espécie de inferencia das exceptions jogadas
por um método, sem obrigar o cara a colocar um monte de throw em tudo
q eh canto ou engolir exceptions pra prototipar e depois esquecer de
tratá-las (como era o db4o antes).

Com isso, a IDE poderia mostrar pro cara, de alguma forma, todas as
exceptions jogadas por um método caso o cara queira tratar alguma
delas. Usando isso no main() poderia ver quais exceptions n sao
tratadas em nenhum ponto do sistema.

Por falar em inferencia e exceptions, em boo tem como fazer algo
similar ao Maybe do Haskell, p eliminar null pointer exceptions?


> > Vc esta falando de tradução boo -> Java ou de Java -> boo? Eu
> > perguntei de boo -> Java.
>
> boo -> java.

Vc teria q, por exemplo, meter um try/catch vazio em toda exception
checada q o codigo em boo esta ignorando, eh isso?

Flw, Klaus.

Rodrigo B. de Oliveira

unread,
Oct 26, 2007, 12:04:34 PM10/26/07
to boo...@googlegroups.com
Using english from now on...

On 10/26/07, Klaus Wuestefeld <klauswu...@gmail.com> wrote:
> ...
> So you mean that it's possible to generate valid JVM bytecode that
> invokes a method that throws a checked exception without catching
> it nor declaring it in the current method?

Apparently, yes.

>
> > > Does boo supports checked exceptions?
> >
> > No.
> Which part of "explicit is better than implicit" you disagree with?

:) I should see that one coming.

I disagree if it comes in the way of "wrist friendlyness", clarity and
DSLness which are my major goals with boo.

> ...
> You know what would be cool? Some kind of exception inference...

Now we're talking.

That could completely implemented through one of the boo meta
programming facilities.
One could for instance implement a module attribute that would make
sure all methods are annotated with any checked exceptions that escape
from it while also checking the annotations of any invoked methods and
warning the user accordingly. Something like:

[module: CheckExceptions]

The syntax above apply the attribute CheckExceptionsAttribute to the
current module (the AST entity that represents a file). The attribute
will be instantiated by the compiler during the compilation process
and it's free to do whatever, even adding checked exceptions.

> ...
> Talking about inference and exceptions, is it possible to have something like
> Haskell's Maybe to eliminate null pointer exceptions?
>...

To some extent, yes. Here's a quick thing I put together just an example:

import Boo.PatternMatching // match
import Boo.Adt // data

class Foo:
pass

def maybeFoo(some):
if some: return Some of Foo(Foo())
return None of Foo()

def test(some):
match maybeFoo(some):
case Some of Foo(value: foo):
print "got some foo: ${foo}"
otherwise:
print "no foo for you"

data Maybe[T] = Some(value as T) | None()

test(true)
test(false)

which will print:

got some foo: Foo
no foo for you

Notice that 'data' and 'match' are not core language constructs but
external macros.

> Talking about a hypothetical boo->java source code translation ...
>
> You would have to insert empty try/catch statements for every checked exception
> ignored by boo, is that it?

Some along that lines, yes.

Reply all
Reply to author
Forward
0 new messages