Propose Trowable as the base class of Error and Exception.

57 views
Skip to first unread message

罗勇刚(Yonggang Luo)

unread,
Nov 17, 2014, 8:38:28 AM11/17/14
to Dart
at the current time, Error and Exception is not related.

--
此致

罗勇刚
Yours
sincerely,
Yonggang Luo

Cogman

unread,
Nov 17, 2014, 10:55:42 AM11/17/14
to mi...@dartlang.org
Throwable ;)

I personally don't think they should be related.  I've done the ole "catch (Throwable ex)" In java and it usually causes more harm than good.  If you need both then I don't see any reason why explicitly catching both is a bad thing.

--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

罗勇刚(Yonggang Luo)

unread,
Nov 17, 2014, 11:02:41 AM11/17/14
to Dart
2014-11-17 23:55 GMT+08:00 Cogman <cog...@gmail.com>:
> Throwable ;)
>
> I personally don't think they should be related. I've done the ole "catch
> (Throwable ex)" In java and it usually causes more harm than good. If you
> need both then I don't see any reason why explicitly catching both is a bad
> thing.
>
It's from hierarchy's point of view, anyway,we can be sure catch(
Throwable ex) is
not acceptable by the compiler.

Matthew Butler

unread,
Nov 17, 2014, 11:37:49 AM11/17/14
to mi...@dartlang.org, luoyo...@gmail.com
Some things to keep in mind. 1) In Dart there is a clear distinction between Error and Exception. An exception is something you can expect to run into (such as invalid input from an end user). Where an Error is usually not something preventable (Out of Memory). Errors should generally stop execution.

2) Everything is Dart is throwable. For example: if(!valid) { throw "Invalid. Throwing String"; }

Matt

Lasse R.H. Nielsen

unread,
Nov 17, 2014, 11:56:13 AM11/17/14
to mi...@dartlang.org
Errors are special in Dart.
They are intended for programming errors, and are not made for being caught. They also have special handling that stores the current stack trace in the error at the time of throwing (if you extend Error and not just implements it).

Exceptions are everything else. There isn't really a need for an Exception class.
You can extend or implement Exception to document that your class is intended for being thrown as a kind of alternative return value for exceptional, but not erroneous, cases. Or you can just use any class that you want.

/L

--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

Cogman

unread,
Nov 17, 2014, 12:01:55 PM11/17/14
to mi...@dartlang.org
At that point, I don't see the value.  We are creating a hierarchy for hierarchies sake. If the hierarchy is essentially non-functional then why make the hierarchy?

This is probably just me, but I've started preferring a pretty flat hierarchy with my programming structures.

Bob Nystrom

unread,
Nov 17, 2014, 12:52:03 PM11/17/14
to General Dart Discussion, Yonggang Luo

On Mon, Nov 17, 2014 at 8:37 AM, Matthew Butler <butler....@gmail.com> wrote:
2) Everything is Dart is throwable.

Except null.

Of course, trying to throw null does throw an exception, so I suppose you can throw null, you just can't catch it. :)

- bob

Lasse R.H. Nielsen

unread,
Nov 17, 2014, 2:04:41 PM11/17/14
to mi...@dartlang.org, Yonggang Luo
On Mon, Nov 17, 2014 at 6:51 PM, 'Bob Nystrom' via Dart Misc <mi...@dartlang.org> wrote:

On Mon, Nov 17, 2014 at 8:37 AM, Matthew Butler <butler....@gmail.com> wrote:
2) Everything is Dart is throwable.

Except null.

I keep forgetting that. It's a silly exception anyway.
 

Of course, trying to throw null does throw an exception, so I suppose you can throw null, you just can't catch it. :)

For consistency, we usually say you *can't* do things that throw when you try to do them. As such, you can't throw null.
You could catch it if you could throw it: ...} on Null catch (e) {...

/L
-- 
Reply all
Reply to author
Forward
0 new messages