🔥 Using Custom Exceptions to write better, clearer code - Laravel

  Рет қаралды 11,630

Mateus Guimarães

Mateus Guimarães

Күн бұрын

Пікірлер: 26
@ward7576
@ward7576 3 жыл бұрын
I could recommend another approach that I learned from Spatie - you can just throw exceptions like so (if you have longer exception messages, but not only): `throw CreditsException::notEnoughCredits();` and the underlying implementation is just bunch of static methods doing this: `return new static('Not enough credits in your account');` where static in this case is the exception class. For me it's really neat since you can hide longer messages in the exception class and as well - define some other exceptions that can be related to credits (that way avoiding a ton of exception classes that throw one exception only)! I hope whoever sees this, deems it as useful, because that really helped me with more clarity and more readable exceptions since I like to be descriptive with my exception messages. Cheers!
3 жыл бұрын
Yep I really enjoy this approach as well! Thanks for commenting!
@Flamestriker42
@Flamestriker42 4 жыл бұрын
This is very helpful. Even if you know how to do custom exception this video still helps. How Laravel handles exception was helpful to me.
4 жыл бұрын
Happy to help!
@mayanksgajjar
@mayanksgajjar Жыл бұрын
Hey bro, Its a great content video. You have explained it in a very nice way.... Thanks and keep up doing great work...
Жыл бұрын
It's my pleasure
@jasonennis4905
@jasonennis4905 4 жыл бұрын
That's some really clean code fham not gonna lie 🇯🇲
4 жыл бұрын
Thanks, Jason!
@bryanastacio5167
@bryanastacio5167 4 жыл бұрын
Really like your content is too specific and helpful, keep going, pal!
@bulent2435
@bulent2435 3 жыл бұрын
That was a good lesson. Thanks.
3 жыл бұрын
Very glad you liked it!
@thevipinchand4690
@thevipinchand4690 4 жыл бұрын
Thanks a ton it's very helpful on daily development.
@murilolivorato1489
@murilolivorato1489 2 жыл бұрын
very good !
@logicalsyntaxerror
@logicalsyntaxerror 4 жыл бұрын
Wow, this is very helpful.
4 жыл бұрын
Thanks, man! Much appreciated. 😊
@jongjinkim8587
@jongjinkim8587 3 жыл бұрын
I'm curious why do I have to handle the exception in the controller? Are there any drawbacks in common processing in the handlers provided by Laravel? If you handle exceptions in the controller, there seems to be too many duplicate codes. What do you think?
@mayanksgajjar
@mayanksgajjar Жыл бұрын
its just a personal choice, where to write code. I am not writing my business logic directly in controllers. I try to keep it simple. So I try to move my logic in service class, actions class, etc
@loremipsum5642
@loremipsum5642 4 жыл бұрын
hi, I have a question. What if the custom exception will be placed in the handler?
4 жыл бұрын
I don't particularly like it because if I look at a controller I can't clearly see what happens, but yes, you can place it on the exception handler.
@mubinsayed
@mubinsayed 3 жыл бұрын
Thanks
@hambaku7318
@hambaku7318 4 жыл бұрын
Your course's link is not working.
4 жыл бұрын
Whoops. My bad. Try now!
@romeosromo6286
@romeosromo6286 4 жыл бұрын
Really nice tutorial. However, It would've been really helpful if you showed us the files directories as well as the Ticket file. For new comers to laravel like me, it is not obvious in what directory some files go.
@gugamito
@gugamito 4 жыл бұрын
Tem alguma maneira de eu contar quantas exceptions foram geradas?
4 жыл бұрын
Fala, Gustavo. Pode ser mais específico? Acredito que $exception->getTrace() você consegue o stack trace.
Ep19 - Laravel Exceptions | Laravel API Server
10:15
Acadea.io
Рет қаралды 8 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 7 МЛН
How To Create Custom Standardized HTTP Responses In Laravel
16:37
What I do before coding complex features
20:35
Mateus Guimarães
Рет қаралды 2,3 М.
Java Custom Exceptions Tutorial - It's Way Easier Than You Think
14:29
Coding with John
Рет қаралды 165 М.
Exceptions in Laravel: Why/How to Use and Create Your Own
12:18
Laravel Daily
Рет қаралды 88 М.
Checked vs. Unchecked Exceptions in Java Tutorial - What's The Difference?
10:14
Modularizing your Laravel Application in a very simple way - Laravel 8
14:18
Junior Code Review: Laravel Routes, Middleware, Validation and more
19:57
Laravel Exceptions in depth | Arabic
20:39
Mahmoud Anwar
Рет қаралды 1,6 М.
Laravel Try-Catch and Exceptions: 5 Examples from Framework Itself
10:32