Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 26, 2008 multi catch | ||||
---|---|---|---|---|
| ||||
How to create few catches? for example: try{ ... } catch(Object o){ ... } catch(Exception e){ ... } |
July 26, 2008 Re: multi catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | On Sat, 26 Jul 2008 05:07:20 -0400, Zarathustra wrote:
> How to create few catches?
> for example:
> try{
> ...
> }
> catch(Object o){
> ...
> }
> catch(Exception e){
> ...
> }
The syntax is ok, but catch(Exception) is never reached.
because Object will also match Exceptions.
I think the compiler will argue about that.
|
July 26, 2008 Re: multi catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | "Zarathustra" <adam.chrapkowski@gmail.com> wrote in message news:g6epg8$24r7$1@digitalmars.com... > How to create few catches? > for example: > try{ > ... > } > catch(Object o){ > ... > } > catch(Exception e){ > ... > } Always order your catches from most-derived to least-derived. So, try { .. } catch(Exception e) { .. } catch(Object o) { .. } That's what the "catch at foo hides catch at bar" means. |
July 26, 2008 Re: multi catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley Wrote:
> "Zarathustra" <adam.chrapkowski@gmail.com> wrote in message news:g6epg8$24r7$1@digitalmars.com...
> > How to create few catches?
> > for example:
> > try{
> > ...
> > }
> > catch(Object o){
> > ...
> > }
> > catch(Exception e){
> > ...
> > }
>
> Always order your catches from most-derived to least-derived. So,
>
> try { .. }
> catch(Exception e) { .. }
> catch(Object o) { .. }
>
> That's what the "catch at foo hides catch at bar" means.
>
>
Ok, thanks It's working.
|
Copyright © 1999-2021 by the D Language Foundation