• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Ducked Exception

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks

I came to know that If there is no catch clause present to catch the exception in code then it is know as Ducked Exception.

Am I on right way or wrong? Please help me.

code:

class Test
{
public static void main(String args[])
{
try
{
throw new Exception;
}
finally
{
System.out.println("ThisisduckedException");
}
}
}
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. As far as main method is concern, you can say that main() is ducking Exception.
[ April 20, 2007: Message edited by: Pankaj Patel ]
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are partially Correct.
This code wont compile because
"Duck eclare the exception and �pass the buck� to some other method to handle or duck again."

So you need to declare a throws clause.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as i know , you can write either catch clause or finally or both


so , as this code throw new Exception it must print "Thisisducked Exception " follows by Exception trace

but its compiling error , why ?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Eisa says,
as i know , you can write either catch clause or finally or both
so , as this code throw new Exception it must print "Thisisducked Exception " follows by Exception trace
but its compiling error , why ?



Yeah, you can write catch clause, finally or both.
But here scenario is different; Ducking the exception never means that you don't declare that exception. We can't break handle or declare rule.

If you are ducking the exception, means you don't want to handle for obvious reason, you must declare that. Here is the running code:



finally block will execute, until there is JVM shutdown, as you may know this already.

This is the case with checked exceptions, unchecked exceptions can go
uncaught and undeclared; compiler wont bother, because it is matter of runtime.




Regards,
cmbhatt
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic