Solved

Try and catch problem

Posted on 2006-07-14
6
186 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
6 Comments
 
LVL 6

Assisted Solution

by:manch
manch earned 250 total points
Comment Utility


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
Comment Utility
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
Comment Utility
So basically what you are saying;

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

Is this right?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Author Comment

by:TommyTwoPints
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now