Do catch block have any limitations ?

Alok mishra
@alok-mishra-E4tgN8 โ€ข Oct 23, 2024

Someone was arguing me that we can not write 'anything we want' in catch block !! Is it so ? Are there any limitations on the code that we put within catch ?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • rahul69

    @rahul69-97fAOs • Sep 13, 2013

    Alok mishraSomeone was arguing me that we can not write 'anything we want' in catch block !! Is it so ? Are there any limitations on the code that we put within catch ?

    Ask that someone to be specific ,as "anything we want" may include a lot of things.
    As u cannot write "Anything u want" inside the main() function, it must be a valid code.


    Regarding catch blocks, if u are trying to catch multiple exceptions in a single catch block (Assuming Java 7), u cannot change the catch parameter inside the catch block.

  • Alok mishra

    @alok-mishra-E4tgN8 • Sep 13, 2013

    rahul69Ask that someone to be specific ,as "anything we want" may include a lot of things.
    As u cannot write "Anything u want" inside the main() function, it must be a valid code.


    Regarding catch blocks, if u are trying to catch multiple exceptions in a single catch block (Assuming Java 7), u cannot change the catch parameter inside the catch block.

    if we write another valid program inside catch that sorts a given array and prints and from try we manually throw an exception then i think catch will successfully sort that array and print .no?