Thread overview
multi catch
Jul 26, 2008
Zarathustra
Jul 26, 2008
Moritz Warning
Jul 26, 2008
Zarathustra
July 26, 2008
How to create few catches?
for example:
try{
  ...
}
catch(Object o){
  ...
}
catch(Exception e){
  ...
}
July 26, 2008
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
"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
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.