[Issue 7540] New: Catch multiple exception types with single catch block
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 18 23:47:52 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7540
Summary: Catch multiple exception types with single catch block
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: yebblies at gmail.com
ReportedBy: yebblies at gmail.com
--- Comment #0 from yebblies <yebblies at gmail.com> 2012-02-19 18:47:51 EST ---
In some cases, multiple exceptions require the exact same handling code in a
catch block, but are not the only children of a common base class.
class MyExceptionA : Exception {}
class MyExceptionB : Exception {}
class MyExceptionC : Exception {}
void main()
{
try
{
trySomething();
}
catch (e : MyExceptionA, MyExceptionB)
{
// handle A and B
}
catch (MyExceptionC e)
{
// handle C a different way
}
}
This avoid the current messy solutions such as duplicating the bodies, using
goto (does this even work?), moving the code to a function, or catching the
base class and using typeinfo to choose.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list