www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - multi catch

reply Zarathustra <adam.chrapkowski gmail.com> writes:
How to create few catches?
for example:
try{
  ...
}
catch(Object o){
  ...
}
catch(Exception e){
  ...
}
Jul 26 2008
next sibling parent Moritz Warning <moritzwarning web.de> writes:
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.
Jul 26 2008
prev sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Jul 26 2008
parent Zarathustra <adam.chrapkowski gmail.com> writes:
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.
Jul 26 2008