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!
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?
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
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.
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!
Yep I really enjoy this approach as well! Thanks for commenting!
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.
Happy to help!
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
That's some really clean code fham not gonna lie 🇯🇲
Thanks, Jason!
Really like your content is too specific and helpful, keep going, pal!
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?
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
Thanks a ton it's very helpful on daily development.
hi, I have a question. What if the custom exception will be placed in the handler?
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.
That was a good lesson. Thanks.
Very glad you liked it!
Wow, this is very helpful.
Thanks, man! Much appreciated. 😊
very good !
Tem alguma maneira de eu contar quantas exceptions foram geradas?
Fala, Gustavo. Pode ser mais específico?
Acredito que $exception->getTrace() você consegue o stack trace.
Thanks
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.
Your course's link is not working.
Whoops. My bad.
Try now!