I think it is worth mentioning that if you really want to catch any Exception or Error, you can catch Throwable, as both Errors and Exceptions do implement it.
Thank for the video. I never thought of catching the error but after this video I had to say small videos like this one can actually help us all to learn new thing. I really appreciate your efforts.
I always recommend caution with the DivideByZero error - sometimes it won't work as you expect! PHP being a bit crackpot at times treats straight-up division by zero as a warning rather than an error, and this can't be caught. To remedy this, always check your inputs before attempting any division.
Thank you for your videos and ideas, Povilas! Watching you almost every day. But I got a bit curious and started to wonder, why use 'App\Model\Thread' instead of Thread:: class, which would significantly reduce chance of typos. Noticed this in other examples and also in Laravel in general, so this is not any expression of negativity or so, just curious
If you have Error you bad developer or you write bad testing code. Catch error is way to hide/miss problem. I see this many times when junior's catch erros and can't fix bug....
Personally, I don't use the try catch much in php because of the sequential flow, for me it is easier to throw new Exception for error handling, on the other hand when I program in java with swing or fx I use it a lot so that the environment does not trigger graphic.
Hey! Just a quick question. I always write "return redirect()->to(route('post.index'));". With you I see "redirect()->route('xy');" Don't you need to set this "to" for routes? Does the "to" perhaps have another purpose? Thanks! ✨
dear sir, how we can check this $names[ ] array variables empty or not( when i'm uploading only one or two images) in here ? Post::create([ 'title' => $request->get('title'), 'details' => $request->get('details'), 'image1' => $names[0], 'image2' => $names[1], 'image3' => $names[2], ]);
if $names is always to be expected as an array then you could do something like: // names not empty if ($names != null) of if you are working with eloquent and collection: // names not empty if (!$names) or // counting names if ($names->count() == 0) I suggest you loop through the $names array to avoid repetition and hard coding.
IDK, but sequentual catch blocks are not that readable (or at least not enjoyable for reading) and honestly they look ugly as hell. I do not see a benefit where the only difference will be in printing either string containing "Exception...." or "Error....." - if u need it user friendly just writhe sth like: "Problem occurred:..." and simply always catch for \Throwable. Both Exceptions and Errors in PHP implement this interface.. Now if you have custom exception class and wish to do some custom logic if it's catched - then you must use another catch block, that's for sure
I think it is worth mentioning that if you really want to catch any Exception or Error, you can catch Throwable, as both Errors and Exceptions do implement it.
Right! Great catch! (pun intended)
Yes !
Neat. We learn every day. I didn't know that, I always thought Throwable was just a generic for Exceptions
I didnt know we could use anything else lol !
What is the difference between Throwable and Exception ?
Hi thanks for the channel.
In some rare cases, I catch \Throwable which is an interface that includes Exception and Error I think.
Thank for the video. I never thought of catching the error but after this video I had to say small videos like this one can actually help us all to learn new thing.
I really appreciate your efforts.
Thanks for all you do sir
from Nigeria
Thanks a lot of, Polivas!! I didn't use /Error. I Think it is good to use it for logging. Or for API, to have a convenient message for front-end
Very useful 😀
Error Handling is one of the most important things for UX
You have 2 inserts inside Try. It might be a good idea to do transaction & rollback to make error handling complete?
thanks a million! it's very useful for me! Your english is very clear)
I always recommend caution with the DivideByZero error - sometimes it won't work as you expect! PHP being a bit crackpot at times treats straight-up division by zero as a warning rather than an error, and this can't be caught. To remedy this, always check your inputs before attempting any division.
What if we use Throwable which catches both General Exception and Errors?
thanks for very helpful topic
Can you please make a video of php arrow function using in laravel
Thank you for your videos and ideas, Povilas! Watching you almost every day. But I got a bit curious and started to wonder, why use 'App\Model\Thread' instead of Thread:: class, which would significantly reduce chance of typos. Noticed this in other examples and also in Laravel in general, so this is not any expression of negativity or so, just curious
That was just a random example when class name may be dynamic as a variable.
Hi Povilas, thanks for videos. Do you have a plan for making a video about Pest testing?
Not at the moment
If you have Error you bad developer or you write bad testing code. Catch error is way to hide/miss problem. I see this many times when junior's catch erros and can't fix bug....
sir what are the use case of DB::transaction...?
ruclips.net/video/7daBdm2xgm8/видео.html
@@LaravelDaily Thank you now I understand the Use Case of DB::transaction....
Thanks as always!!
Personally, I don't use the try catch much in php because of the sequential flow, for me it is easier to throw new Exception for error handling, on the other hand when I program in java with swing or fx I use it a lot so that the environment does not trigger graphic.
what is the use of DB::transaction...?
ruclips.net/video/7daBdm2xgm8/видео.html
Hey! Just a quick question. I always write "return redirect()->to(route('post.index'));".
With you I see "redirect()->route('xy');"
Don't you need to set this "to" for routes? Does the "to" perhaps have another purpose?
Thanks! ✨
No there's no need to write to(), not sure why you write it :)
dear sir, how we can check this $names[ ] array variables empty or not( when i'm uploading only one or two images) in here ?
Post::create([
'title' => $request->get('title'),
'details' => $request->get('details'),
'image1' => $names[0],
'image2' => $names[1],
'image3' => $names[2],
]);
if $names is always to be expected as an array then you could do something like:
// names not empty
if ($names != null)
of if you are working with eloquent and collection:
// names not empty
if (!$names)
or
// counting names
if ($names->count() == 0)
I suggest you loop through the $names array to avoid repetition and hard coding.
@@daleryanaldover6545 problem is it cannot check in create method in store function. Inside create method cannot use if() .
@@daleryanaldover6545 done. Thanks for the helping
❤
@@chameeradinesh1221 use mergeWhen() function.
respect ... live long King
I have encountered that divide by 0 error a long time ago and laravel catched it in develop mode.
Good to know ! Thank you
@@Towzlie😂
make tutorial laravel inertia reactjs. Please.
Hello there...
I have 2 different blade view coming from 2 different controllers.
How can I merge the two views into one pdf file with single click...
IDK, but sequentual catch blocks are not that readable (or at least not enjoyable for reading) and honestly they look ugly as hell.
I do not see a benefit where the only difference will be in printing either string containing "Exception...." or "Error....." - if u need it user friendly just writhe sth like: "Problem occurred:..." and simply always catch for \Throwable. Both Exceptions and Errors in PHP implement this interface..
Now if you have custom exception class and wish to do some custom logic if it's catched - then you must use another catch block, that's for sure
First comment