473,473 Members | 4,208 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

question about exception

51 New Member
The following I try to execute function 'my_test()' only if it exists. But anyway if 'my_test()' doesn't exist, it will stop there before 'echo'.

[PHP]try {
xtest();
} catch (Exception $e) {}

echo 'Hello World';[/PHP]


jack
Oct 14 '08 #1
3 1093
Dormilich
8,658 Recognized Expert Moderator Expert
you could test the function with function_exists(). if you want to use try-catch you have to throw an exception to make it work.

regards
Oct 14 '08 #2
Atli
5,058 Recognized Expert Expert
Hi.

You can use the set_error_handler function to set your own error handler, which could throw an exception.

But... it will not work for fatal errors, such as the on your non-existing function would cause. Such an error is considered the equivalent of a Java *compile error*, which the code itself would not be able to handle.

Exceptions are meant to handle runtime errors. Fatal errors will always stop your code, despite your error or exception handling. (In theory at least)

You would need to use the function_exists function, like mentioned in the previous post.
Oct 14 '08 #3
datactrl
51 New Member
Thank you so much everyone. Got it to work now by using function_exists().

Jack
Oct 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Gonçalo Rodrigues | last post by:
Hi, For error processing I found convenient maintaining a dictionary where the keys are exception *classes* and the values are callables. Of course, for this to work, exception classes have to...
1
by: serge calderara | last post by:
Dear all, How can I handle correctly cascading exception? I generally use to catch exception ib all my function. This to identify each type the correct place that the exception occurs. What...
12
by: Mark | last post by:
Apologies for the lengthy posting.... In a previous posting:...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
5
by: Gelios | last post by:
Hello All! I am going to crazy and feeling myself so stupid but I don't understand such behaviour. I have code: public int getNextAgentId() { Int32 agent_id = 0; IDataReader dr =...
7
by: Tiraman | last post by:
Hi , I am using allot the try catch in my code and the question is if it is good ? it will decrease my performance ? one more question
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
10
by: tony | last post by:
Hello!! As you know every user defined exception must be derived from class Exception. Now to my question if I write catch then every exception will be caught. If I instead write...
0
by: robert | last post by:
Hi all, I'm having a hard time resolving a namespace issue in my wsdl. Here's an element that explains my question, with the full wsdl below: <definitions name="MaragatoService"...
5
by: Vijay | last post by:
Hi All, I am not able to figure out what exactly happening in below code. what is control flow. Can anyone clear my confusion? Code: class A { public: A(){cout<<"In Constructor\n";}
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.