8.9异常捕获与file

本文深入探讨了Java中异常处理的基本概念,包括运行时异常和编译异常的区别,以及如何使用try-catch-finally和throws关键字进行异常管理。通过具体代码示例,详细解释了ArithmeticException、ArrayIndexOutOfBoundsException和NullPointerException等常见异常的捕获与处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.异常捕获

public class TestException {
    public static void main(String[] args)  {

        //1.ArithmeticException
        //2.ArrayIndexOutOfBoundsException
        //3.NullPointerException
        /**
         try {
         int i = 2 / 0;
         System.out.println("111111111");
         }catch(ArithmeticException e){
         System.out.println("除数不能为0 ");
         }finally {
         System.out.println("22222222222");
         }
         **/
        div(1,0);
        //    Class.forName("11111");



    }

    static int div(int a,int b) throws ArithmeticException{
        int c=a/b;
        return c;
    }

    //异常处理方式:   1.jvm 处理   运行java程序的抽象计算机  异常名称  异常信息 异常出现的位置
    //               2.自己处理   (1) try  catch  finally
    //                             (2)  throws

    //所有异常的父类都是Exception

    //异常的类型
    //1.运行时异常  extends RuntimeException
    //2.编译异常   必须自己处理

}

2.file

运行报以下错误,如何解决 Loaded checkpoint from ./trained_models/nyuv2/r34_NBt1D.pth I0000 00:00:1742470009.822851 1296506 gpu_device.cc:2019] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 3088 MB memory: -> device: 0, name: NVIDIA GeForce RTX 4090 D, pci bus id: 0000:51:00.0, compute capability: 8.9 I0000 00:00:1742470009.823513 1296506 gpu_device.cc:2019] Created device /job:localhost/replica:0/task:0/device:GPU:1 with 464 MB memory: -> device: 1, name: NVIDIA GeForce RTX 4090 D, pci bus id: 0000:c3:00.0, compute capability: 8.9 [ WARN:0@3.446] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/labels/image_0726_label.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.446] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/depth/image_0729_depth.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.447] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/rgb/image_0724_color.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.448] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/depth/image_0737_depth.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.448] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/rgb/image_0748_color.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.449] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/labels/image_0734_label.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.449] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/rgb/image_0732_color.png.png'): can't open/read file: check file path/integrity [ WARN:0@3.450] global loadsave.cpp:268 findDecoder imread_('./datasets/nyuv2/test/rgb/rgb/image_0740_color.png.png'): can't open/read file: check file path/integrity 报错这些是什么问题,如何解决
最新发布
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

干饭人小周26

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值