Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Try and catch problem

Posted on 2006-07-14
6
Medium Priority
?
192 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:TommyTwoPints
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Assisted Solution

by:manch
manch earned 1000 total points
ID: 17107033


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
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 17107034
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
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17107059
So basically what you are saying;

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

Is this right?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17107069
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
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 17107227
Hi,
yes ,you have to use try and catch again for the commands on the called forms.


Regads
pradeep
0
 
LVL 6

Accepted Solution

by:
Nandakumar Sakthivel earned 1000 total points
ID: 17107277
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question