I answered the same question before in a previous
post..Anyway let me type it again...
You do not have to do anything to bubble up an exception
to the calling code, which is the parent form in this
case. Think it this way, When you get an exception in your
code, and you do not handle it, CLR gives a message saying
that there is an exception and what do you want to do with
it, (i.e; Abort, Retry, Continue options). Here CLR is the
parent code which invoked the assembly (exe in many
cases) of your program, and your program caused an
exception and it is never handled anywhere int he
heirarchy of caling, so eventually the control comes to
CLR which handles by showing that message to us..
So the answer for the question is this.validate().. What
you are doing in the second case is, you are handling the
exception and then throwing it explicitly, even in this
case the exception is bubbled up to parent form, but you
are making it in two steps, which is unnecessary..
You can also test with a code similar to the following,
void parent_method()
{
try
{
childMethod();
}
catch(Exception e)
{
Console.WrtieLine("Child Exception caught);
}
}
void childMethod()
{
this.Validate();
}
You would get the "Child exception caught" if this.Validate
() generates an exception.. that means exception bubbled
up automatically to the calling code..
I hope i am clear enough..
>-----Original Message-----
>Interesting... never thought of it that way... lol....
got my exam in 2
>days... will have to be more careful...
>
>--
>Regards,
>
>HD
>
>"john sermini" <> wrote in message
>news
--dne7DZZQah3KiRVn-...
>> I think that you are both correct. It would be correct
to say that if you
>> don't trap the exception that the parent would catch
it. But the questions
>> states that you want the error to be bubbled up, so I
think that implies
>> that you want to catch the exception, and then re-throw
it. So I think
>that
>> B is the correct answer for the way that the question
is worded.
>>
>>
>> "Hermit Dave"
<> wrote in message
>> news:eqx$Z$...
>> > Think if the parent is trapping the exception... you
dont need to do
>> > anything.. cause if the current method encounters an
exception and it is
>> not
>> > handled... it will be passed to calling function if
that handles the
>> > exception.. you are sorted...
>> >
>> > so i would go with
>> > A.
>> > this.Validate();
>> >
>> > --
>> > Regards,
>> >
>> > HD
>> >
>> > "Christian Ista" <mailing-> wrote
in message
>> > news:...
>> > > Hello,
>> > >
>> > > In a test, I have this question :
>> > >
>> > > You must ensure that any exceptions encountered by
Validate are
>bubbled
>> up
>> > > to the parent form. The parent will be responsible
fo handling the
>> > > exceptions. Accomplish this goal by the minimum
amount of code
>> > >
>> > > A.
>> > > this.Validate();
>> > >
>> > > B.
>> > > try{
>> > > this.Validate
>> > > }
>> > > catch(Exception ex){
>> > > throw ex;
>> > > }
>> > >
>> > > C.
>> > > try{
>> > > this.Validate
>> > > }
>> > > catch(Exception ex){
>> > > throw ("My Exception"ex);
>> > > }
>> > >
>> > > D.
>> > > public class MyException:ApplicationException{
>> > > public MyException():base(){
>> > > }
>> > >
>> > > public MyException(string message):base(message){
>> > > }
>> > >
>> > > public MyException(string message, Exception
inner):base(message,
>> > inner){
>> > > }
>> > >
>> > > }
>> > >
>> > >
>> > > The right answer is B right ?
>> > >
>> > > Thanks,
>> > >
>> > >
>> > >
>> >
>> >
>>
>>
>
>
>.
>