OOP Error Handling In PHP - Exceptions & Try Catch Finally Blocks - Full PHP 8 Tutorial

  Рет қаралды 32,831

Program With Gio

Program With Gio

Күн бұрын

Пікірлер: 120
@asdasx392
@asdasx392 Жыл бұрын
I have been programming for 30 years and got throw onto a PHP project with no prior experience in the language. These are probably the best programming tutorials I have seen. Very fast paced and all the right information.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙏🙏
@dev_troy8903
@dev_troy8903 9 ай бұрын
agreed 👍
@Armando-px8hi
@Armando-px8hi Жыл бұрын
Honestly by making this course everyone who is gonna watch it will make it to the pro. There are many many courses for money but all they explain is just basic knowledge and 4 fundamental concepts of OOP. I have never known about autoloading for example and so much more. Thank you GIO. May GOD BLESS YOU.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you so much 🙏
@darom_96
@darom_96 3 жыл бұрын
Honestly, this channel is pure gold 👌
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thank you 🙏
@dancingdev1088
@dancingdev1088 2 жыл бұрын
Its so much of a gold that it should be on a decentralized server
@wahyunurarizky3860
@wahyunurarizky3860 2 жыл бұрын
factos
@LegendofGopher
@LegendofGopher Жыл бұрын
@@dancingdev1088 XD
@judeleon8485
@judeleon8485 Жыл бұрын
This is so for the most detailed tutorial on Exception I have come across. Thanks a million
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Happy to hear 🙌
@yanushevitz5588
@yanushevitz5588 2 жыл бұрын
Program: "throws an error" Gio: "as you see, everything is working" Great video, thanks for your hard work
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
🤣🤣. Sometimes exceptions are expected 😂. Thank you
@ardavanansari
@ardavanansari 3 жыл бұрын
Wow. Absolutely beautiful ! Thank you for all the hard work you put into this, it shows
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thank you 🙏
@benjaminvenezia1944
@benjaminvenezia1944 Жыл бұрын
Gio is the ultimate argument against the bearded ones who criticize the use of tutorials for learning. I'm waiting for the Laravel tutorial as a Christmas present.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙌. I'm working on a video where I share my plans for 2023, should be fun :)
@mwaas
@mwaas Жыл бұрын
All instructors who present courses on Udemy and Coursera ...... ,should learn from you how to explain all the things and details( not just the basic stuff) in a simple and accurate way.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 💙💙
@ClawHammer23
@ClawHammer23 3 жыл бұрын
I can confirm, this channel is pure gold
@benderbg
@benderbg 3 ай бұрын
Another phenomenal lesson from Gio. The only thing I was having trouble with is that EVERY time I was creating a custom exception class I would somehow forget to put in the App\Exception namespace. The IDE would just chill not warning me about it but the code wouldn't compile even when I manually added the namespace path. So the only solution was to delete and create same class but this time adding the namespace in the creation form itself.
@ProgramWithGio
@ProgramWithGio 3 ай бұрын
That's strange, probably something else was an issue
@iamprincemuel
@iamprincemuel 2 ай бұрын
I used declare strict-types in each php file... that's probably why I didn't face this issue
@Vitalii-m6r
@Vitalii-m6r Жыл бұрын
This is by far the best PHP course. Thanks!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 💙
@bijianwu5124
@bijianwu5124 2 жыл бұрын
thanks for the time and effort you put into making this remarkable content!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you for watching & following along 💙💙
@aleksandrkanygin2672
@aleksandrkanygin2672 9 ай бұрын
Just wanted to thank you gio, got a really good job probably because of your course :)
@ProgramWithGio
@ProgramWithGio 9 ай бұрын
That's awesome, congratulations. You got the job because of you, you are the one who put in the work & learned, so congrats again
@JonasHerbertson
@JonasHerbertson 3 жыл бұрын
Greeeeeat tutorial! Thank you so much - exactly what I was looking for :)
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Glad to hear that, thank you 🙌
@vivamedia5958
@vivamedia5958 3 жыл бұрын
Thank you sooooo much.... Really really helpful and awesome! looking forward for more from you.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
You're welcome & thank you 🙌
@acuteclub7381
@acuteclub7381 Жыл бұрын
bravo, very well explained.... you should be teaching it, keep up the good work and thanks a lot for the effort
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thanks a lot 🙏
@federicobau8651
@federicobau8651 2 жыл бұрын
Great video, thanks Gio
@Zubbee
@Zubbee 2 жыл бұрын
Great lesson. First exposure to this kind of error handling. I certainly need to explore it more... later. I need to move on, want to get to the end of section 2. Thanks a lot Gio
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Awesome, thank you 🙌
@truthteachers
@truthteachers Жыл бұрын
Bro, this is the best and detail explanation on PHP exceptions. Now i know i could throw my own custom exceptions for database access errors. Only thing is my old complain - too fast. But its ok, i repeat the portion in slow speed.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you. Speed gets better in 3rd section 🙌
@ieduardoms
@ieduardoms 9 ай бұрын
You always give very valuable tips. Thank you so much.
@ProgramWithGio
@ProgramWithGio 9 ай бұрын
Happy to help
@isaacsouza17
@isaacsouza17 3 жыл бұрын
Awesome, helped me better understand exceptions when using Laravel, thanks bro, keep it up.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Glad to hear that, you're welcome and thank you 🙏
@karam0101
@karam0101 2 жыл бұрын
I hit the thumbs up before watching, thank you bro
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 🙌
@mikulcek
@mikulcek Жыл бұрын
Your work is careful crafted.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙌
@ינוןאלבז-כ1ז
@ינוןאלבז-כ1ז Жыл бұрын
Very informative very enriching very helpful, thanks for this awesome tutorial!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Happy to hear that, you're welcome
@ClawHammer23
@ClawHammer23 3 жыл бұрын
c'mon people..... 2.524 visits and only 144 likes? what's wrong with you guys....hit that damn thumbs up
@devonmclean4337
@devonmclean4337 2 жыл бұрын
Awesome content! very verbose and thorough
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 🙌
@emekatimothyiloba699
@emekatimothyiloba699 Жыл бұрын
Thank you Once Again Gio
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome 🙌
@apl1mhd
@apl1mhd Жыл бұрын
Pure gold, take a love ❤
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you
@christophrumpel
@christophrumpel 2 жыл бұрын
Nice one Gio 👍
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you Christoph 🙌
@timiade8108
@timiade8108 3 жыл бұрын
Thanks
@FranciscoJunior29
@FranciscoJunior29 2 жыл бұрын
Great content, it's awesome
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
I'm glad you like it, thank you
@lairotuT-Tutorial
@lairotuT-Tutorial 2 ай бұрын
Really great lesson! Does it make sense to include a "MyAppException"-trait that e. g. includes logging of Exceptions, Handling-Options like communicate to the user, closing the app, returning to last input page and so on and then use this trait in all self-made Exceptions? In addition I would have an interface that contracts the usage of various instructions that clarify which options from the trait or from php built in methods shall be used. Do you consider the above mentioned too complex and maybe creating bad readability - in other words would you suggest to rely on what PHP serves us with?
@ProgramWithGio
@ProgramWithGio 2 ай бұрын
Might be overly complex & that trait would have too many responsibilities
@zubair.mohsin
@zubair.mohsin 3 жыл бұрын
Cool music and effects 👌
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thanks 🙂
@soumadip_banerjee
@soumadip_banerjee 2 жыл бұрын
Subscribed ❣️
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you
@memack101
@memack101 2 жыл бұрын
Thank you.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome
@ilya_123__
@ilya_123__ Жыл бұрын
thank you!
@ProgramWithGio
@ProgramWithGio 11 ай бұрын
You're welcome!
@Rimtay
@Rimtay 11 ай бұрын
Awesome🎉
@ProgramWithGio
@ProgramWithGio 11 ай бұрын
Thanks 💙
@artemdev110
@artemdev110 3 жыл бұрын
Thanks for the video. If I have my whole application code inside try/catch block with Throable, is there any reason to use the set_error_handler and/or set_exception_handler ?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Set exception handler is pretty much same as global try/catch. I would use exception handler though just in case some exception isn't caught, it will be surely caught by the exception handler
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Set error handler can also catch notice and warnings which you can't catch using try/catch so that's one reason to use it if u want to have custom handling of notice/warnings
@artemdev110
@artemdev110 3 жыл бұрын
@@ProgramWithGio Thanks!!
@emekatimothyiloba699
@emekatimothyiloba699 Жыл бұрын
Nice
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thanks
@godmansarah
@godmansarah 2 жыл бұрын
1. Could you remind me why you prefix Throwable or Exception with a backslash? I know you mentioned this in a previous video. Thanks! 2. If someone misses a space between `Throwable` and `$e`, will that cause an issue? (Noticed it in an existing file - VSCode with both PHP Code Sniffer and PHP CS Fixer doesn't seem to be complaining).
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
1. Yes we covered this in namespaces lesson, it will try to load that class from local namespace & fail since you probably won't have Throwable class in your own namespace, so either you have to import it or add backslash to load it from global space. 2. Honestly I did not know that this was allowed, I would not rely on it though and just always include the space
@sefyankehail7801
@sefyankehail7801 2 жыл бұрын
First of all thank you so much for everything. I just have a question regarding the last part of the video where you used static methods, I just wanna know the reason behind using late static binding in the return statements ( return new static('Missing billing info'); ), is it because maybe we will use another class that extends the InvoiceException class, or there is another reason for that ? new self would also be fine here right ?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Yes, correct. Self would work as well, static just future proofs that part since its common to use inheritance with exception classes.
@sefyankehail7801
@sefyankehail7801 2 жыл бұрын
@@ProgramWithGio clear, thank you so much 🖤🙏
@z3ko
@z3ko 3 жыл бұрын
Thanks for another great lesson. One question, on 11:09 mark in the video, should we in php7 and php8 always use \Throwable instead of \Exception (in that situation) ?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
You're welcome. In general yes, \Throwable is better, but I like to catch specific exceptions so if its an exception about an argument being invalid, I throw InvalidArgumentException & catch that, if its an error during some calculation then I would throw custom exception & catch that and so on. I try to avoid \Exception & \Throwable & be explicit whenever possible. I talk about Exception & Throwable at 15:15. In the example at 11:09 the proper way was right before that at 7:58, at 11:09 I just wanted to show an example of what happens if you catch \Exception
@sym2574
@sym2574 Жыл бұрын
Should I write exceptions in the whole program?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Depends on what exceptions you want to catch, but in general you should have a proper exception/error handling throughout your application
@gabrielpirvu670
@gabrielpirvu670 3 жыл бұрын
What editor are you using?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
phpstorm
@gustavomanzano3360
@gustavomanzano3360 2 жыл бұрын
I made the same as you: Try/Catch blocks with my custom exception class who is an extension of the generic exception class, but it's not working i received an global errorhandler message instead of the exception of my custom class... i dont get how it should work...
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Hard to say without seeing the code. Can you push your code to GitHub & send me the link? I can check & help you troubleshoot it. You can also DM me on Twitter 👍
@gustavomanzano3360
@gustavomanzano3360 2 жыл бұрын
@@ProgramWithGio Here is it github.com/gumanzanoo/php-custom-exception Thank you for your help! Well, I tried to implement in a similar way to what I saw in your video. But if you clone the repository and access the /Exception web route, you will see that the error is returned by the standard ErrorException class instead of my CustomException class which is in the catch block. When I hover over the call of the CustomException class, the IDE shows a message 'Exception 'CustomException' is never thrown in the corresponding 'try' block. I don't know why the catch is not handling the exception with my custom class, because the class extends Exception 😰
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
@@gustavomanzano3360 the custom exception isn't being thrown from anywhere within the try block so that's why your IDE is graying it out, where are you throwing the exception from?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
@@gustavomanzano3360 you don't have custom exception handler defined & not throwing the custom exception from anywhere so that's why it's not working the same way. Try to set it up the same way as it is in the video. DM me on Twitter and I can explain it further if needed
@NedumEze
@NedumEze Жыл бұрын
Hi Gio, Sorry to trouble you, please. May I ask, how do you use the Static Exceptions in try/catch blocks? I have a Database Class, say, In the Constructor, I have this: try { $this->pdo = new PDO (......); } catch (DatabaseException $e) { ???? } In my DatabaseException Class, I have: Public static function ConnectionFailureException() which returns new static('.....');
@ProgramWithGio
@ProgramWithGio Жыл бұрын
I show an example of that in the video around 18:49
@NedumEze
@NedumEze Жыл бұрын
@@ProgramWithGio Thank you Gio. I watched the clip again. And, it showed the usage when you have a Custom Exception Handler or the default Exception Handler. But, it didn't handle usage of the Static flavor in try/catch blocks.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
I dont really understand what you mean by static flavor?
@NedumEze
@NedumEze Жыл бұрын
I mean this way of defining Exceptions Classes: Public static function ConnectionFailureException(){ return new static( .... ); } When I need to throw this Exception in the try block, it's as simple as: throw new Database::ConnectionFailureException(); But, when I have a try/catch block, in the catch block I have: catch( DatabaseException $e){ echo $e->getMessage(); ???? } How should the expression in the catch block be written to utilize the static Exception definition in the catch block? Is it okay to still say the usual $e->getMessage(), $e->getCode(), etc.?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
@@NedumEze yea I show such example in the video at that timestamp, it's a static method and then we throw it from the other class. Method is static not the entire class, so you still access the object methods regularly in catch
@DirectorCouch
@DirectorCouch 2 жыл бұрын
What IDE are you using ?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
PHPStorm
@TheArmanist
@TheArmanist 3 жыл бұрын
Set an exception handler: set_exception_handler(function (\Throwable $e){ var_dump($e->getMessage()); }); echo array_rand([], 1); but it still shows: Warning: array_rand(): Array is empty in C:\Users\Dell\Desktop\forks\quantum-php-project\public\index.php on line 22
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
You are on PHP 7.4 probably, I mentioned that at 17:22, it throws exception since PHP8, prior to PHP8 it triggers warning & warnings cant be caught with an exception handler or try/catch block. Warnings & notices can be caught by using the error handler that we discussed in the first section of the course (the procedural way of handling errors).
@JonasHerbertson
@JonasHerbertson 3 жыл бұрын
How do you add the method in phpstorm?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
What do you mean?
@JonasHerbertson
@JonasHerbertson 3 жыл бұрын
@@ProgramWithGio Sorry, that was a bit short I guess 😅 - on 19:57 you create a class and shortly later a method via a shortcut. I was wondering what kind of shortcut(s) that was.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
@@JonasHerbertson ah, alt + enter
@JonasHerbertson
@JonasHerbertson 3 жыл бұрын
@@ProgramWithGio Great! Many thanks! 😊
@BubblegumSoup
@BubblegumSoup 2 жыл бұрын
good channel, talks a bit slow though…
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you. Yes, I'm trying to improve on that 💙
@photoshopologi1445
@photoshopologi1445 2 жыл бұрын
thats great but pleassse talk slower
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you. Yea I improved on that in third section.
@truthteachers
@truthteachers Жыл бұрын
Thanks
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you for support 💙
PHP - DateTime Object - Full PHP 8 Tutorial
25:30
Program With Gio
Рет қаралды 23 М.
PHP Traits - How They Work & Drawbacks - Full PHP 8 Tutorial
31:41
Program With Gio
Рет қаралды 33 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,6 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 177 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 7 МЛН
Advanced Exception Handling in Python
12:06
NeuralNine
Рет қаралды 66 М.
JavaScript Error handling in 9 minutes! ⚠
9:03
Bro Code
Рет қаралды 17 М.
PHP doesn't suck (anymore)
10:48
Aaron Francis
Рет қаралды 210 М.
PHP Error Handling & Error Handlers - Full PHP 8 Tutorial
7:30
Program With Gio
Рет қаралды 48 М.
Static Properties & Methods In Object Oriented PHP -  Full PHP 8 Tutorial
12:58
PHP Enums With Practical Examples - Full PHP 8 Tutorial
28:13
Program With Gio
Рет қаралды 26 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,6 МЛН