Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
2 answers
506 views

Requiring query field to not be empty on search api

we have a RESTful API that includes an endpoint for search apiserver/v5/search?q=[search text] for any query, it passes it off to solr and returns the result like ...
AwokeKnowing's user avatar
5 votes
2 answers
9k views

Should i throw exceptions in the service layer or repository, and catch it on the controller? [closed]

I read some answers here on stack exchange, but none really "hits the nail on the head" about where to throw exceptions, where I shouldn't and where to catch them. the idea that an exception ...
Thiago Dias's user avatar
3 votes
2 answers
191 views

Library displaying a format with runtime errors, exceptions, and error exceptions present

I have this Library to control errors; I would like if you can evaluate it and make a review of the code, not about the goals of the library: Everything works for me correctly, but I am also open to ...
user avatar
5 votes
2 answers
654 views

Mysql PDO Wrapper that throws Unique Constraint Exception

The main reasoning behind this PDO wrapper, is that I find myself using unique constraints quite frequently in my designs, and I have ...
bumperbox's user avatar
  • 2,106
1 vote
1 answer
214 views

Handling multiple try-catches in a for loop

Good day! I would like to know if this is possible to be refactored into a cleaner code. The reason I'm doing it like this is to catch the column that the error appeared on and then potentially output ...
Chansters's user avatar
1 vote
1 answer
151 views

Connect to database, handling errors

I try to handle or catch possible errors with PHP/MySQL for security reasons and would like to know if I'm doing it right. The first case, connection: I use it as a function and call it always when ...
Nino's user avatar
  • 21
5 votes
2 answers
132 views

A simple but useful error handler

I am trying to make a very simple error handler that would catch and handle all kinds of errors in both development and production environments. The idea is to keep it as simple as possible yet useful ...
Your Common Sense's user avatar
4 votes
3 answers
211 views

PHP display Error Wanings Yellow @ bottom of Page with PHP_EOL

I initially started searching for a PHP script which would output PHP errors, to the JavaScript console. As the Default behaviour is just to spit them out anywhere and displace everything else. ...
Ryan Stone's user avatar
2 votes
1 answer
72 views

PHP function to check if something valid or return error message [closed]

I would like to make a function that checks if something is valid, but if it can't then I want to return an error message that will probably be used to to throw an exception. ...
Jonathan Clark's user avatar
3 votes
1 answer
554 views

PHP Error handler class

I set up an error handler class to handle all server errors, I know there are already quite a few out there, but I like creating my own for better learning and understanding of how things work. I am ...
K.D's user avatar
  • 133
2 votes
1 answer
693 views

PHP LDAP credentials validation and error handling

I developed this group of scripts to validate users againts a LDAP server and presenting the appropiate message to the user after sending the information. I wonder if I'm handling everything properly ...
Jh62's user avatar
  • 133
0 votes
2 answers
194 views

Custom Error Classes in OOP

I have a class which parses a .csv file and converts it into successful rows and errors. Currently I have 12 different kind of errors (mail is not valid, missing column x, row is duplicate etc.). ...
Adam's user avatar
  • 345
4 votes
3 answers
783 views

Using PHP explode() to parse multi-part error messages

I am dealing with a system which sends any unexpected errors back to me in a string, for example: ...
sam's user avatar
  • 243
2 votes
1 answer
12k views

MySQLi query and error handling for select, insert, and update

I am creating a new webpage with database connection. I want to make sure that I am handling the MySQLi query correctly for Search, Insert, and Update. I also want to make sure if any errors do pop up,...
John Williams's user avatar
2 votes
1 answer
116 views

Function to insert a tag into a database

I'm developing a MVC structured RESTful API project (thanks to the help of Mārtiņš Tereško for explaining it). Almost all of my functions look similar to this: ...
DaAmidza's user avatar
  • 249
0 votes
2 answers
310 views

Handling missing elements on login form in Selenium

I try to improve my code so that I don't have to program a try - catch block all the time. e.g. at the moment I have to write many codeblocks like this: ...
Black's user avatar
  • 243
2 votes
2 answers
405 views

PHP Error Class

I have coded a very simple error class that will allow me to display errors if they should happen. For example, if a file is missing or a database connection couldn't be established I would display a ...
Louis Paterson's user avatar
1 vote
1 answer
2k views

Prettifying PHP's Exception stacktraces

I have always disliked the way PHP printed stacktraces, coming from a Java world. So I decided to implement my own ExceptionFormatter, a class that will format ...
Pieter van den Ham's user avatar
1 vote
1 answer
77 views

Validation of uploading images and adding records to the database

I am doing a php project with the codeigniter framework. In my controller, I have a function that does the following. Uploads an image to the server Add a row to the database. The data would be ...
lightning_missile's user avatar
3 votes
1 answer
524 views

Uploading multiple files using a class

Below I have implemented a class that will validate and upload files based on the specified rules. ...
Mikey's user avatar
  • 382
1 vote
2 answers
11k views

Validating username, password, and email in PHP

Let's pretend the following: ...
Ramon Bakker's user avatar
2 votes
2 answers
788 views

Validating user credentials and logging into a Symfony site

I have the following code in a Symfony site that validates a user's credentials and logs them in via the Session class: ...
Robert Calove's user avatar
2 votes
2 answers
199 views

Many nested session verification conditions

Can someone give me advice on cleaning this code? It's more messy then I expected. I got like 10-15 more ifs to be added. I've thought of adding the error messsages in methods and then just check if ...
Sami Samiuddin's user avatar
5 votes
2 answers
792 views

Throw an exception which contains a nested set of previous exceptions

I have a set of domain objects which try to find a solution to a problem. The top level object has an algorithm which splits up the problem and delegates it to lower level objects, which in turn do ...
Jayy's user avatar
  • 340
3 votes
1 answer
1k views

Custom error/fatal error and exception handler in PHP

Introduction I wrote three functions that aims to log errors and exceptions as well as show a user a generic error page. Would appreciate some feedback on it with regards to the PSR standards and if ...
kexxcream's user avatar
  • 225
2 votes
0 answers
561 views

Dynamically created Exception classes

This is a question about best practices. I have a project I am building and I have the following base Exception class: ...
ArtisticPhoenix's user avatar
2 votes
1 answer
408 views

Custom error handler for PHP

I've written a custom Error handler for use in PHP. What it does is simply capture PHP errors, and logs them using Monolog. It works, but I can't help that it has too much stuff inside. I could ...
Loupax's user avatar
  • 219
4 votes
1 answer
172 views

Custom 503 page for MySQLi connection error

I redirect all my requests to index.php via htaccess and the code below is in my index.php. Is this code properly set for a custom 503 page for an unsuccessful MySQLi connection trial? Is it also ...
Andre Chenier's user avatar
1 vote
1 answer
325 views

Handling errors when using PDO to connect to a database instead of MySQLi

What would be the preferred method for handling errors when using the PDO to connect to a MySQL database? I was using mysqli_error($this->pdo), but I heard this ...
zia grosvenor's user avatar
0 votes
1 answer
78 views

Setting error reporting based on config

...
Donny's user avatar
  • 35
2 votes
1 answer
2k views

Is this the right way to handle Exceptions in PHP?

I'm using the function countLikes() to fetch URLs' Likes count from the Facebook API. ...
ahmed's user avatar
  • 121
1 vote
1 answer
2k views

When should I call set_exception_handler with this exception handler class?

This is a simplified version of ExceptionHandler.php: ...
Josh Harrison's user avatar
2 votes
1 answer
2k views

Nested try/catch with PDO in PHP

I would like to know if this is the correct way to use try/catch when dealing with multiple MySQL queries and PDO: ...
ThomasK's user avatar
  • 347
4 votes
1 answer
8k views

Throwing an exception within a try/catch block in PHP

Is there a cleaner way to do this? ...
Lloyd Moore's user avatar
4 votes
2 answers
861 views

PHP and MySQLi login script - is it secure / am I doing something wrong?

Below is the code for my login page. I haven't really used MySQL (especially OOP) before, so I'd like to know if I'm doing something inherently wrong. The code is working as expected, but I don't ...
nvbmnbvm's user avatar
1 vote
1 answer
1k views

Usage of try/catch and database transactions

I am using try/catch syntax in combination with a database transaction to (hopefully) prevent partial registrations. I am ...
r3wt's user avatar
  • 472
4 votes
2 answers
19k views

Checking empty object

Is there a better method for covering errors in my case? I am looking for best practice for now and future instances. Foreseen errors that could arise: No attributes at all Some attributes could be ...
dnelson's user avatar
  • 143
4 votes
1 answer
284 views

Throw exception in favor of an error?

I've been reviewing my previous projects for the last few days. I've found that I never return an error from any of my methods. I always throw exceptions. I googled about exceptions vs errors and I ...
Moon's user avatar
  • 378
8 votes
1 answer
5k views

Yii exception usage

I've never used a framework before, so I wanted to see if this fairly simple scenario was done correctly or could be improved: ...
Jonnny's user avatar
  • 285
6 votes
1 answer
12k views

Catching all exceptions and errors in PHP

I've tried to catch all exceptions and errors in PHP in a way so that I can deal with them consistently. This is the code with the exception of the very last bit where I instead pass ...
Svish's user avatar
  • 298
3 votes
2 answers
201 views

error handling logic in php [closed]

I'm wondering if you see anything terribly wrong with this code, or if you see any areas for improvement. My objective is to make sure its simple enough for someone else taking over my job to be able ...
dot's user avatar
  • 181
5 votes
1 answer
3k views

Try/catch block in PDO wrapper

I have written a PDO wrapper and a class file like a model. It's looking good so far, but I'm just confuseed on where I should put the try/...
I'll-Be-Back's user avatar
1 vote
3 answers
282 views

Fail-safe remote API operations for managing customers and billing

I'm working with two remote APIs: one which manages customers and the other (a Paypal API interface) which manages billing. To delete an account, I must delete the records from both. ...
waitinforatrain's user avatar
1 vote
1 answer
551 views

PHP - Is this proper use of exceptions for error handling within classes?

I've searched plenty on this topic and have gotten a lot of good (but different) results. Some of the results weren't quite related and it does seem to be a matter of preference in the end, but I'm ...
Daniel Elkins's user avatar
3 votes
1 answer
759 views

PHP error handling: log everything, and redirect critical errors to an "oops" page

I'm VERY new to error/exception handling, previously just echoing everything to screen, and am trying to really clean up my code. My goal was to log everything but only show the user a friendly "oops"...
Isius's user avatar
  • 133
2 votes
2 answers
212 views

extending Exception to allow for auto appending class name on exception message

Got this idea from the php.net website on extending exceptions. The main thing I wanted with this was to have the exception name auto imprinted on the exception message, so I wouldn't have to write it ...
cs_brandt's user avatar
  • 123
2 votes
1 answer
75 views

How can I improve CreateGenre() function?

I use this function in my wordpress site to add genres to an album: What is it that makes this code so bulky? Is it have for the server or it just looks like? ...
Junaid Qadir Shekhanzai's user avatar
2 votes
3 answers
386 views

Collecting form errors to be displayed

I have a piece of code that get errors from form and display to view: ...
hungneox's user avatar
  • 171
3 votes
2 answers
287 views

Is it acceptable to pass an Exception into a function that then may or may not throw it?

I am still getting the hang of Exception Handling in PHP; Here is the scenario where I am using the convention: There are times where I have a SQL query that I need to turn into an object, so I wrote ...
Shad's user avatar
  • 193
6 votes
2 answers
461 views

User error logging

I have created this code for user error logging, and I am wondering if there is anything that can be improved. The point is that this error handler would ONLY catch user errors created in-code by ...
dqhendricks's user avatar