Answered by:
Try catch not catching problem with AD search

Question
-
If I do a search0.FindAll() and it throws the error for "server is not operational" I want to catch it but am not having success. Here is the code to put into a button click event:
Try Dim x as integer = 1 Dim y as integer = 0 x = x/y Catch ex As ApplicationException MessageBox.Show("catch: " & ex.ToString()) End Try MessageBox.Show("out of try")
My debug exe is updating the changes I have tried so what else is there?
please help
CountryStyle- Edited by CountryStyle Thursday, August 6, 2009 2:31 AM
Thursday, August 6, 2009 2:21 AM
Answers
-
Kaymaf said:
Exception : Represents errors that occur during application execution. (common language runtime). If this error occur, your program cannot compile.
This is not quite true. Since exceptions occur at run-time the compiler cannot detect them so it will compile your program.
There are two broad types of exception: System.SystemException and System.ApplicationException.
Both inherit from System.Exception.
A System.SystemException is thrown by the CLR (i.e. .Net run-time) and means something drastic has gone wrong and the program probably cannot continue. This forms the base class for exceptions such as ArgumentOutOfRangeException and DivideByZeroException. So to trap divide by zero errors you need to catch either catch DivideByZeroException explicitly or catch System.SystemException (or plain System.Exception since this is base for both broad types, but this is not good practice).
A System.ApplicationException can be thrown by your program so you are free to create your own specialist exceptions. This is useful if you have some error condition that the runtime won't detect and you want to make sure it is handled. You could derive your application exceptions directly from System.Exception but best practice dictates you derive them from System.ApplicationException.
- Proposed as answer by Waleed El-Badry Thursday, August 6, 2009 9:57 AM
- Marked as answer by CountryStyle Thursday, August 6, 2009 8:43 PM
Thursday, August 6, 2009 9:13 AM -
figured it out.....duh.....
I replaced "ApplicationException" with "Exception"
the default of the IDE is "Exception" and I somehow changed it......now I want to find out what the diff is. If someone knows off the top of their heads please post.
thanks for reading.
PS: mods....delete thread if it is a waste of space/time...I wont mind
Exception : Represents errors that occur during application execution. (common language runtime). If this error occur, your program cannot compile.
ApplicationException : Exception that is thrown when a non-fatal application error occurs. Read more about this at http://msdn.microsoft.com/en-us/library/system.applicationexception(VS.80).aspx
kaymaf
I hope this helps, if that is what you want, just mark it as answer so that we can move on- Proposed as answer by Waleed El-Badry Thursday, August 6, 2009 10:00 AM
- Marked as answer by CountryStyle Thursday, August 6, 2009 8:43 PM
Thursday, August 6, 2009 4:25 AM
All replies
-
ok first of all. in the exception handing...i think you must throw the exception if you didn't throw it how can he know the wrong thing..
like this..
try
if not isnumeric(text) then
dim err as new exception "put the error here"
throw err 'to throw the err
catch ex ...
messagebox.show(ex.message)
i think this is you proble right knowThursday, August 6, 2009 2:29 AM -
figured it out.....duh.....
I replaced "ApplicationException" with "Exception"
the default of the IDE is "Exception" and I somehow changed it......now I want to find out what the diff is. If someone knows off the top of their heads please post.
thanks for reading.
PS: mods....delete thread if it is a waste of space/time...I wont mindThursday, August 6, 2009 2:34 AM -
Hi Here is a Code That Handle the exception .
Try Dim x As Integer = 1 Dim y As Integer = 0 x = x / y Catch ex As Exception MessageBox.Show("catch: " & ex.ToString()) Finally MessageBox.Show("out of try") End Try
Greetings
Melvin.
Todo Es posible si se studia con exfuerso no importando lo de mas, Dios esta con nosotros y no hay mas sabiduria que la de Dios, Everything is posible Do not Turn Off Your Mind Remember Our Decision is Give EveryThing that We have , God Loves us Today Tomorrow and Always... Melvin Saludos U.S.A- Proposed as answer by Waleed El-Badry Thursday, August 6, 2009 9:57 AM
- Unproposed as answer by CountryStyle Thursday, August 6, 2009 8:43 PM
Thursday, August 6, 2009 2:58 AM -
figured it out.....duh.....
I replaced "ApplicationException" with "Exception"
the default of the IDE is "Exception" and I somehow changed it......now I want to find out what the diff is. If someone knows off the top of their heads please post.
thanks for reading.
PS: mods....delete thread if it is a waste of space/time...I wont mind
Exception : Represents errors that occur during application execution. (common language runtime). If this error occur, your program cannot compile.
ApplicationException : Exception that is thrown when a non-fatal application error occurs. Read more about this at http://msdn.microsoft.com/en-us/library/system.applicationexception(VS.80).aspx
kaymaf
I hope this helps, if that is what you want, just mark it as answer so that we can move on- Proposed as answer by Waleed El-Badry Thursday, August 6, 2009 10:00 AM
- Marked as answer by CountryStyle Thursday, August 6, 2009 8:43 PM
Thursday, August 6, 2009 4:25 AM -
Kaymaf said:
Exception : Represents errors that occur during application execution. (common language runtime). If this error occur, your program cannot compile.
This is not quite true. Since exceptions occur at run-time the compiler cannot detect them so it will compile your program.
There are two broad types of exception: System.SystemException and System.ApplicationException.
Both inherit from System.Exception.
A System.SystemException is thrown by the CLR (i.e. .Net run-time) and means something drastic has gone wrong and the program probably cannot continue. This forms the base class for exceptions such as ArgumentOutOfRangeException and DivideByZeroException. So to trap divide by zero errors you need to catch either catch DivideByZeroException explicitly or catch System.SystemException (or plain System.Exception since this is base for both broad types, but this is not good practice).
A System.ApplicationException can be thrown by your program so you are free to create your own specialist exceptions. This is useful if you have some error condition that the runtime won't detect and you want to make sure it is handled. You could derive your application exceptions directly from System.Exception but best practice dictates you derive them from System.ApplicationException.
- Proposed as answer by Waleed El-Badry Thursday, August 6, 2009 9:57 AM
- Marked as answer by CountryStyle Thursday, August 6, 2009 8:43 PM
Thursday, August 6, 2009 9:13 AM -
Well said Riced. Kaymaf gave the same answer in an indirect way :-)
Cheers
Waleed El-Badry Teaching Assistant Faculty of Engineering Misr University for Science & TechnologyThursday, August 6, 2009 9:58 AM