All Questions
Tagged with exceptions php
26 questions
1
vote
3
answers
306
views
Should you reuse a PHP exception's code when wrapping it?
When catching and wrapping an exception in PHP, assuming the new exception doesn't have a meaningful code of its own, should you also use the caught exception's code value? or the default value? In ...
3
votes
6
answers
164
views
How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?
Consider class Crate that is a value object. Crate represents a valid 3-dimensional box.
In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters ...
2
votes
2
answers
247
views
Should you "rebrand" the exception of the library you're using?
Say your making a library Foo that depends on a 3rd-party library Bar.
Bar throws a custom exception \OtherVendor\Bar\CustomException.
Is it recommended to just throw that exact exception to your ...
1
vote
1
answer
111
views
What kind of exception of SPL is best suited for file exceptions?
When I use the Exception provided by the SPL the options are limited. So it's hard to pick which exception would be best suited to handle File exceptions.
I know the best scenario is to write my own ...
6
votes
3
answers
367
views
Are exceptions only for handling errors?
I have a script that throws exceptions when something goes wrong. However, for the purposes of testing I also want to capture specific points although I'm not sure whether they would be deemed errors ...
3
votes
1
answer
2k
views
How often should I use try/catch statements? [duplicate]
Everything I've read says that they should be used when something that simply "shouldn't happen" does happen. But the thing is, there's a lot of things that could go wrong.
For example, if I'm ...
3
votes
2
answers
677
views
Advantages of extending the default Exception class
I've seen that it's possible to extend the default Exception class in PHP, enabling one to throw an IncorrectParameterTypeException exception, or a ValueOutOfRangeException exception (maybe these are ...
0
votes
1
answer
2k
views
Can I execute a query in a catch block of try-catch? [duplicate]
I want to confirm the right approach of using try-catch exception handler.
I have written a query in a try block, and if any exception is thrown, it will execute a query in a catch block.
Is this ...
2
votes
4
answers
1k
views
Where should PDOExceptions be dealt with?
I wrote a database wrapper class to help with queries and I'm trying to figure the best way to implement try-catch blocks.
In my database class, I have a helper function;
public function fetchAll($...
2
votes
3
answers
571
views
Is an application supposed to recover from a exception thrown in PHP?
What if the programmer uses Exceptions for debugging? Would it be better in that case to just report the failure and immediately interrupt the script since ideally all bugs should be fixed radically?
...
3
votes
3
answers
246
views
Extended usage of an exception
I'm in the process of building a routing system for learning purposes and have encountered an issue which I think is a bit in the grey area of best practices. Can you guys help me decide if this is ...
1
vote
1
answer
174
views
Using exceptions as regular objects [duplicate]
I have views that handle different errors in my application. For example error 404, 403 and such, giving my errors a more user-friendly presentation. By assumption, they get passed in an exception, so ...