Try and catch problem

Hi Experts,

I have an issue with try and catch and was wondering if there was any way around it

In my form code on all the top level commands i have

Try
'Call
Catch ex as exception
'Error Code
End try

Most of the calls load another form and will run through alot of routines but it still all leads back to the first call in the form code. Why arent my errors handled by this?

Cheers,

Tom
LVL 3
TommyTwoPintsAsked:
Who is Participating?
 
Nandakumar SakthivelConnect With a Mentor Technology LeadCommented:
It depends on how do you want
ie.,

private sub main()
Try
      subfunction()
     <some code here>
Catch ex as exception
end try
end sub

Private sub subfunction()
try
  <some code here>
catch ex as exception
End Try

   In the above case if any exception occurs in the subfunction means it is handled there itself.The exception is not thrown to the main function.Here the code next to the function call in main function will also be executed.

In this case

private sub main()
Try
      subfunction()
      <some code here>
Catch ex as exception
end try
end sub

Private sub subfunction()
try
  <some code here>
catch ex as exception
  throw ex
End Try
  In the above one the exception is caught in sub function and thrown to the main function.So in the main function code next to the functioncall will not execute.


Thanks,
Nanda
0
 
manchConnect With a Mentor Commented:


For the Inner most catches u have to throw the exception again
becuase the Error is already encoutered with the inner catch statement

e.e.

Try

 Call a()
Catch ex as exception

end try


Private sub a()

try
  call b()
catch ex as exception
   'handle the error if u want
  'or u can throw the error if u want it should be handled to the calling routine

End Try
0
 
Nandakumar SakthivelTechnology LeadCommented:
Hi,
  In the called form you might have handled all the exceptions(using try catch and might not have used throw in the catch block).If you want to handle the exceptions here you need to throw the exception in the called forms catch code.

Thanks,
Nanda
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
TommyTwoPintsAuthor Commented:
So basically what you are saying;

Use try and catch again for the commands on the called forms.

Is this right?
0
 
TommyTwoPintsAuthor Commented:
The reason i asked this is because i had Try and catch code in the top level routine in another application. If any error occured in any of the lower level routines it was handled by the catch in the first routine.
0
 
pradeepsudharsanCommented:
Hi,
yes ,you have to use try and catch again for the commands on the called forms.


Regads
pradeep
0
All Courses

From novice to tech pro — start learning today.