D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8140 - allow to catch exceptions by implemented interface
Summary: allow to catch exceptions by implemented interface
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-24 05:22 UTC by luka8088
Modified: 2020-01-16 13:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description luka8088 2012-05-24 05:22:09 UTC
Now we can only catch by class that is derived from Throwable. This prevents logical generic *grouping* and catching by *group*. As discussed in #d on freenode irc from 24-05-2012 13:20:00 to 24-05-2012 13:56:00.

For example:

// assume that IThrowable is in druntime

interface IMyException1: IThrowable {}
interface IMyException2: IThrowable {}
interface IMyException3: IThrowable {}

class MyException1: Exception, IMyException1 {}
class MyException2: Exception, IMyException1, IMyException2 {}
class MyException3: Exception, IMyException1 ,IMyException3 {}
class MyException4: Exception, IMyException3 {}

try {

  throw new MyException2();

} catch (IMyException3) {

  // catches MyException3 or MyException4

}
Comment 1 Mathias LANG 2020-01-16 13:47:53 UTC
Closing as WONTFIX.

Rationale: This is an enhancement request, but there doesn't seem to be much interest in it, and the rationale is limited. Proper exception hierarchy is something that is often theorized but very rare in practice, and D is no exception (pun intended).
If you strongly feel like we should pursue this, feel free to open an DIP: https://github.com/dlang/DIPs