STOP SWALLOWING EXCEPTIONS 🤮

Ғылым және технология

Java Exception handling is key for any backend application. In this video I discover this flaw in a code review.
Please never do this.
Don't Forget to
===========================================
💯 Subscribe to Amigoscode - bit.ly/2HpF5V8
💯 Courses Available for free here - amigoscode.com/courses
💯 Join Private Facebook Group and Discord - amigoscode.com/p/join-community
🙊 Here are the goods for all my videos video 🙊
► Recommended Books
===========================================
- Clean Code - amzn.to/2UGDPlX
- HTTP: The Definitive Guide - amzn.to/2JDVi8s
- Clean Architecture - amzn.to/2xOBNXW
► Computer and Monitor
===========================================
- New Apple MacBook Pro - amzn.to/3464Mmn
- Dell 27 INCH Ultrasharp U2719D Monitor - amzn.to/2xM3nW1
- Double Arm Stand Desk Mount - amzn.to/3aYKKfs
- USB C Hub Multiport Adapter - amzn.to/2Jz7NlL
► Camera Gear
=============================================
- Sony ILCE7M3B Full Frame Mirrorless Camera - amzn.to/346QIJn
- Sigma 16 mm F1.4 DC DN - amzn.to/2wbic3Q
- Sigma 33B965 30 mm F1.4 DC DC - amzn.to/39G37Fd
► IDE & Tools I use for coding 💻 🎒
===========================================
- ITerm
- VsCode
- GoLand
- IntelliJ Ultimate
- Sublime
P.S
===========================================
💯 Don't forget to subscribe | bit.ly/2HpF5V8
💯 Join Private Facebook Group and Discord - amigoscode.com/p/join-community
💯 Follow me on Instagram | bit.ly/2TSkA9w
❤️ Thanks for watching

Пікірлер: 73

  • @praveens2272
    @praveens2272 Жыл бұрын

    I always tell my juniors never ever swallow exceptions, in rare cases we don't need to rethrow or wrap it. We could just log the error.

  • @vitormuuniz
    @vitormuuniz Жыл бұрын

    STOP SWALLOWING EDITION! IT WAS MUCH BETTER THE OLD WAY

  • @89Valkyrie
    @89Valkyrie Жыл бұрын

    Incredible advice. Thank you.

  • @oogway_hussein
    @oogway_hussein11 ай бұрын

    thank you, your video teaches me using intellij and luckily, the shortcuts are same than pycharm, it is better slowly learning intellij for me than looking at the pdf and i don't forget easily this way

  • @orionpaul5210
    @orionpaul5210 Жыл бұрын

    thanks Nelson I actually dropped nodejs back to springboot saving some little fund for your master class you make Java go simple

  • @martingomes8641
    @martingomes8641 Жыл бұрын

    Sometimes we need to handle checked exceptions from an external API and it enforces you to use try-catch Block, i think the appropiate way in this case is retrow the exception. I also agree with the approach of handle exceptions with proper status code.

  • @martingomes8641

    @martingomes8641

    Жыл бұрын

    Another thing to be aware is to not rethrow complete exception, sometimes exceptions have sensitive data to be exposed.

  • @dunayqudretli3382

    @dunayqudretli3382

    11 ай бұрын

    yeah, In checked exceptions you don't need to catch exception also, just throws exception to the spring boot, then handle it from advice and return according status code to the client

  • @codeexperience9998
    @codeexperience9998 Жыл бұрын

    You are always awesome Nelson ❤️❤️❤️

  • @Asingh42
    @Asingh42 Жыл бұрын

    Hey! Been watching your tutorials since a long time.. Can you make tutorials on reactive programming using spring web flux ?

  • @MsSWAGboss
    @MsSWAGboss9 ай бұрын

    GREAT content!Keep it up👏👏

  • @divakarpandey9094
    @divakarpandey9094 Жыл бұрын

    Grt bro !! Thanks for the suggestions I am ATG developer from India. Sometimes I do like this.

  • @Take19797
    @Take1979710 ай бұрын

    the try and catch was made for the .save method except that method could also throw its exception if it faced error while logging in the database so really there was no need for the try and catch unless the catch had something useful to do which didn't in this case but also sometimes the the handler (try-catch block) is made by force because the .save method can throw an exception therefore the API enforces the rule on you

  • @sainarsimhaguptathammana9908
    @sainarsimhaguptathammana9908 Жыл бұрын

    Hi Nelson, Thank you🤝 for the wonderful lessons. I am a java developer, currently i have been working on one project where I have to process/validate against 50-60 rules, each rule is created as a class due it's complexity. Now these many classes I have to inject into the service class for the processing... In the service class I am using the switch case to process the desired rule. Could you please suggest any solid dependency injection pattern or another way here. Thank you in advance!

  • @orlandolorenzodeveloper

    @orlandolorenzodeveloper

    6 ай бұрын

    Hello, you can use the Factory pattern

  • @somebodyoulove
    @somebodyoulove Жыл бұрын

    In a case where the code is unable to save to the DB say a network connection issue or DB is out or down won’t the try catch come in handy. Or does he/she check at every instance if the DB connection is up/accessible before saving into it.

  • @FG-td4vs

    @FG-td4vs

    Жыл бұрын

    no, a 500 error should be returned in the case of an error like that

  • @Asingh42
    @Asingh42 Жыл бұрын

    The starting sequence was hilarious 😂😂

  • @jeick3645
    @jeick3645 Жыл бұрын

    thank you Jedi master

  • @devoiddude
    @devoiddude Жыл бұрын

    Could you do a demo on this please? very interesting topic.

  • @rrrel756
    @rrrel756 Жыл бұрын

    I'm not familiar with java. But shouldn't employeeRepository.save(employee) be checked for insertion error? Does the JPA automatically throws an error?

  • @thejavaacademy-18

    @thejavaacademy-18

    Жыл бұрын

    Actually Jpa doesn't automatically throw errors. But then you have the option to handle errors in your service class as well as use some quite useful annotations for input validation. All of these ensure you won't have an error while saving an object

  • @centfox
    @centfox Жыл бұрын

    1:56 Could you please tell us why the try-catch is not needed when there is no checked exception? What if the persistence fails?

  • @ds_world2468

    @ds_world2468

    Жыл бұрын

    He means to say that do not send status code 200 if any exception is occurred. Handle and throw an appropriate status code and message here or use controlleradvice for the same

  • @lengors7327
    @lengors732710 ай бұрын

    The amount of code I've looked at that doesn't swallows exceptions and doesn't use status code or uses it poorly since I started working on the industry is astonishing (and I've been working for 5 months only lol). But not so surprising when I've had to work with APIs that use GET requests to put/post/patch data

  • @orlandolorenzodeveloper

    @orlandolorenzodeveloper

    6 ай бұрын

    Yep, same here When I have some time, I just do refactoring work and then create a new branch with the refactored code ready to be merged with the main branch (of course I write tests before changing anything complex)

  • @imdadabro4118
    @imdadabro4118 Жыл бұрын

    Great one.

  • @khazsilverstar
    @khazsilverstar Жыл бұрын

    What about an exception thrown in a secundairy non-business critical process? Thow it upstream and catch it at the uppermost service level?

  • @caffeinejavacode1475

    @caffeinejavacode1475

    Жыл бұрын

    Clickbait video

  • @jamesraphael8473
    @jamesraphael8473 Жыл бұрын

    Thanks bro ❤

  • @vidhya821
    @vidhya821 Жыл бұрын

    separate video on exception handling will be appreciated

  • @ranjanpandey2225
    @ranjanpandey2225 Жыл бұрын

    He might be hungry. So he swallowed the whole exception😂❤

  • @maroofali4723
    @maroofali4723 Жыл бұрын

    The 200 OK example is hilariuos 🤣🤣🤣

  • @jamalkb5912
    @jamalkb5912 Жыл бұрын

    it's okay because client side code can handle the returned value

  • @abu-dukhan
    @abu-dukhan Жыл бұрын

    Thanks man. I hope the we all learn something here which we have in Sha Allah. And please Nelson, can you make a video on multiple implementation of UserDetaisService and a custom authentication provider so that one can authenticate users from different tables. I think that will help a lot, because I'm struggling to do that for about 3 to 4 days now, I did some research and the only thing I found was I have to use WebSecurityConfigurerAdapter which is now deprecated. It'll be a big help if you'll do that for use, especially me. JazaakAllahu khairan. May Allah increase you in knowledge and wisdom. Assalamualaikum

  • @UberDurable
    @UberDurable Жыл бұрын

    Nice tip, and I have a selfie with Cameron Diaz!

  • @im_aditya_rathi
    @im_aditya_rathi Жыл бұрын

    What's wrong with the code, I wasn't able to find it. Why does this give the error in case of status 200. The catch block will only execute in case it finds any Exception then why this is wrong. (can someone explain to me)

  • @friedec3622

    @friedec3622

    Жыл бұрын

    The server will send 200 OK to the client, regardless the request is fail or successfull. Since the catch only log the error. Moreover, it will save null data to the database.

  • @im_aditya_rathi

    @im_aditya_rathi

    Жыл бұрын

    Thanks Friedec, I got it now 😊.

  • @hamdiaminehkh
    @hamdiaminehkh Жыл бұрын

    hi, For my case i send as response an Object named ReturnObject = {"codeException": , "messageException": , "data"} with code 200. if there is no exception the "data" attribute contains the Result Object . if there's an excetion i send codeException and messageException. So allways i have ResponseStatus = 200. And in FRONT i manage the response in Interceptor. If i do this , it's considered as a swallow exceptions?

  • @caffeinejavacode1475
    @caffeinejavacode1475 Жыл бұрын

    Guys Interview question for you: Why there is no cheched exception here, do we need, what about SQLException?

  • @nghiao4427

    @nghiao4427

    Жыл бұрын

    Wait someone

  • @caffeinejavacode1475

    @caffeinejavacode1475

    Жыл бұрын

    @@nghiao4427 I know answer but video not cover this topic

  • @nghiao4427

    @nghiao4427

    Жыл бұрын

    @@caffeinejavacode1475 Oh so what is answer? Please tell me

  • @minimovzEt

    @minimovzEt

    Жыл бұрын

    Most likely handled by a exception handler class, you will intercept most common exceptions there and only rethrow if you need a specific or custom exception

  • @breakofsadness9629

    @breakofsadness9629

    Жыл бұрын

    Hibernate wraps it in the Runtime Exception?

  • @michatchorzewski4272
    @michatchorzewski427211 ай бұрын

    Heh I saw something like this in production code... Fixing this is painful

  • @friedec3622
    @friedec3622 Жыл бұрын

    statuscode: 200 message: "Mission failed successfully"

  • @jameszaman3326
    @jameszaman3326 Жыл бұрын

    Anyone know what IDE and font he is using?

  • @sanchitsingh6900

    @sanchitsingh6900

    Жыл бұрын

    IDE is IntellijIdea and font is default one

  • @Quillraven
    @Quillraven Жыл бұрын

    At least he was logging something. I saw code where the developer just added a comment in the catch block like // ignore. Most likely he thought that this error will never happen but unfortunately it did and it took me quite some time to find that place and finally be able to debug it and fix the problem. It was some parsing shenanigans with date and number and obviously the format changed at some point which made his code no longer work 😅

  • @bayembackembaye8969
    @bayembackembaye8969 Жыл бұрын

    😂😂 amazing

  • @martinmiano8220
    @martinmiano8220 Жыл бұрын

    I will admit that I do this when creating microservices. Generally, I record a request to the appropriate request table and if and when it fails, I curate a response code and message that details exactly where the action failed. I prefer to curate detailed response code and message rather than just error 500 that show just that an internal exception occurred.

  • @default_client
    @default_client Жыл бұрын

    i was doing this last friday hahahaha and i made the error harder to identify

  • @heyyrudyy404
    @heyyrudyy404 Жыл бұрын

    I heard exceptions making everything exceptional… so I proceeded to swallow them all 😋

  • @garbi..
    @garbi.. Жыл бұрын

  • @dixztube
    @dixztube Жыл бұрын

    lol I can see why folks don’t ask for help

  • @sacmaliyoruz
    @sacmaliyoruz Жыл бұрын

    the real problem is exceptions :)

  • @gustavotargino6336
    @gustavotargino6336 Жыл бұрын

    200 = failed successfully

  • @ericbroun4657
    @ericbroun4657 Жыл бұрын

    آفرین

  • @guyswithhoodie3572
    @guyswithhoodie3572 Жыл бұрын

    why did you remove my course from the website which I paid for. and now since you increased the price of that course you are offering me only $15 refund. This is not acceptable.

  • @sagargandale4510
    @sagargandale4510 Жыл бұрын

    novice code just like me but i do little bit better

  • @test9828alpha
    @test9828alpha Жыл бұрын

    LGPTQ+ and muslim how come ?

  • @Rubik1325
    @Rubik1325 Жыл бұрын

    I dont know if this was a Java or After Effects tutorial, so annoying

  • @mm1nt
    @mm1nt Жыл бұрын

    Like ur vids but you are editing too much, its not it

Келесі