3 Replies - 223 Views - Last Post: 29 January 2013 - 07:13 PM Rate Topic: -----

#1 mzeezee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-January 13

How to Handle This Exception

Posted 29 January 2013 - 05:03 PM

Dear Friends

I am trying to use EXCEPTION HANDLING for the first time. I have used the following code in my program:

        Dim checkvalue As Boolean = False
        Try
            checkvalue = SaveImOrder()
            checkvalue = SaveImOrderDetails()
        Catch ex As Exception When checkvalue = False
            Exit Sub
        End Try
        (Rest of the code)



In above mentioned functions I am actually saving records in tables and in case of any error returning "FALSE" back here ... Then I need to catch this FALSE value to exit SUB .... However the code is not working and I am unable to track my mistake .. Please help or advice something better

Best Regards

ZEE

Is This A Good Question/Topic? 0
  • +

Replies To: How to Handle This Exception

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4316
  • View blog
  • Posts: 12,096
  • Joined: 18-April 07

Re: How to Handle This Exception

Posted 29 January 2013 - 05:19 PM

What is happening when you run the code? you say it is not working, but what is it doing? Is it not doing anything? Is it highlighting a line as a problem?

I assume that your SaveImOrder() SaveImOrderDetails() are defined as throwing an exception right? Why are you setting checkvalue to begin with if checkvalue is set to false from the start? Doesn't it just make sense to do...

Dim checkvalue As Boolean = False

Try
    SaveImOrder()
    SaveImOrderDetails()
Catch ex As Exception When checkvalue = False
    Exit Sub
End Try



... assuming that those two functions you have there actually throw exceptions. :)

This post has been edited by Martyr2: 29 January 2013 - 05:19 PM

Was This Post Helpful? 0
  • +
  • -

#3 mzeezee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-January 13

Re: How to Handle This Exception

Posted 29 January 2013 - 05:26 PM

Thanks for the reply Martyr

I got error in 1st function "SaveImOrder" and the returned value was FALSE but the flow went to next function without catching the exception. Below is the code of "SaveImOrder":

    Private Function SaveImOrder() As Boolean
        Dim checkvalue As Boolean = False
        SetOrderValues() 'Setting values in objects' variables
        checkvalue = ObjOrder.Insert_Record()
        Return checkvalue
    End Function
 

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3231
  • View blog
  • Posts: 10,851
  • Joined: 12-December 12

Re: How to Handle This Exception

Posted 29 January 2013 - 07:13 PM

You say you get an error but you'll have to disable, or revise, your error handling code to see the error message(s).

Or is it just that (I suspect) your function returns False which does not create an Exception. The following

Catch ex As Exception When checkvalue = False

won't be executed unless an actual Exception occurs - not just because you set the variable to False.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1