gpt4 book ai didi

java - try block 给出编译错误

转载 作者:行者123 更新时间:2023-12-01 23:28:46 25 4
gpt4 key购买 nike

我尝试在我的代码中使用 try block ,但它给出了编译错误。代码是:

    public static void main(String[] args) 
{
try
{
//my logic goes here
return;
}
}

请帮忙解决问题。

最佳答案

没有 catch/finally block 就不能使用 try block 。

你的代码应该是这样的:

    public static void main(String[] args) 
{
try
{
//mu logic goes here
return;
}
catch (Exception e)
{

}
}

    public static void main(String[] args) 
{
try
{
//mu logic goes here
return;
}
finally
{

}
}

或者它可以有多个 catch,但在任何组合中只有一个 finally。

refer to java docs for basic learning of try-catch

关于java - try block 给出编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19636302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com