Exception 自定义

自定义Exception 在完成某一功能时,我们经常会想让程序能够处理某些特定的异常,来增强程序的健壮性。然而JDK中定义的异常类是有限的,因此对于某些特定的异常,我们要通过自定义异常的方式将其捕获。 首先,所有的自定义异常都继承了Exception类 自定义Exception只需要实现构造器方法 public class AttributesNumException extends Excep... 阅读详情

 public class AgeOutofBoundsException extends  Exception{
 private static final long serialVersionUID = 8299254917638606334L;

 

 public AgeOutofBoundsException(){
  super("年龄超出范围");
 }
 
  public AgeOutofBoundsException(String message)   {
     super(message);
   }
}

 

 

public class People {
     private int age;


 public People( int age,) throws AgeOutofBoundsException {
     if(age<1 || age>200)
     {
      throw new AgeOutofBoundsException();
     }
     this.age = age;
 }

 

 

 public void setAge(int age) throws AgeOutofBoundsException {
  if(age<1 || age>200)
  {
   throw new AgeOutofBoundsException("年龄不在1--200之间:"+age);
  }
  this.age = age;
 } 

 
 public int getAge() {
  return age;
 }

  
}

 

OpenCV实战(1)——OpenCV与图像处理基础 OpenCV 是一个跨平台计算机视觉和机器学习库,实现了图像处理和计算机视觉方面的很多通用算法。本节将介绍 OpenCV 的基础知识,以及如何编译运行 OpenCV 程序,并介绍如何完成最基本的图像处理任务——读取、显示和保存图像。除此之外,鼠标事件和图形绘制也是 OpenCV 计算机视觉项目中常用的基本功能,本节介绍了如何使用这两个重要的 OpenCV 功能。 阅读详情

相关推荐

相机通用类之海康相机,软触发硬触发(飞拍),并输出halcon格式对象

如何显示图像:可以访问我文章开头的博客,通过编写相机通用类即可,程序中是有继承通用类,通过访问相机通用的获取图像数据,从而传输图像数据。具体可以查看相机通用类。整体过程其实比较简单,由于海康相机没有像一些品牌相机一样可以直接使用序列号开启相机,所以我们需要通过对相机信息进行索引,根据索引到的相机序列号来开启相机。

m0_51559565的博客 7619

自定义异常

当Java中提供的异常不能满足我们的需求时,我们可以自定义异常定义异常类写继承关系提供空参构造提供带参构造

大蟑螂的博客 133

【S32K】S32K144入门笔记(4) Lin (Lin stack组件) 驱动超声波雷达实例

0. 引言 Lin这块是我一直没弄懂的部分。很多东西一知半解,当时感觉是硬凑了答案出来。 果然过标的时候出了问题,几个小伙伴帮忙一起刷夜也没搞定,好在标还是顺利过了,不然罪过大了。 之前做lin这块一直用的是linStack组件,这部分包含了协议栈部分,需要对lin的协议比较清楚和理解才好配置。 尤其是,图形界面配置完成后会生成一个ldf文件,这个文件很重要,所有的代码都是基于这个文件生成的,但是这个文件我确认没找到什么介绍资料,所以很多配置都是一点一点凑出来的,再实际验证的。 抓住这次写文档的机会,把当时

YoYo的桃子树 1万+

Java异常的学习

温故而知新,异常是Java的入门知识,熟练的掌握可以有效的处理程序中的运行错误,添加代码的健壮性。这里主要记录下自己的学习,理解以及总结。一、什么是异常?异常程序出现的不正常情况。publicvoid方法()throws异常类名{}}}}System.out.println("请输入年龄");try{System.out.println("请输入一个整数");System.out.println("年龄超出了范围");}}提示这里对文章进行总结例如。............

PP东博客 319

Debian 11 下用hostapd+dnsmasq搭建WiFi热点:从命令行到实战(避坑指南)

本文详细介绍了在Debian 11系统上,使用hostapd和dnsmasq从命令行搭建稳定WiFi热点的完整实战流程。内容涵盖环境准备、无线网卡AP模式检查、服务深度配置,并重点提供了从服务启动失败到客户端无法上网等常见问题的系统性排错指南,帮助用户避开配置陷阱,成功创建可用的无线接入点。

CAT789的专栏 769

避开奸商套路!手把手教你用Thaiphoon Burner和CPU-Z,一眼看穿内存SPD信息有没有被篡改

本文教你使用Thaiphoon Burner和CPU-Z工具,快速识别内存SPD信息是否被篡改,避免购买到虚标频率或假冒颗粒的内存条。通过详细步骤和实战案例,帮助用户掌握内存检测技巧,确保硬件购买的透明度和安全性。

weixin_32228501的博客 679

java之异常处理Exception的应用和自定义异常类的应用

Exception 当我们在运行程序的时候,经常会遇见系统报错,其实系统在下面打印出来的是一个异常类的返回值和异常的文件夹和位置 异常类的父类是Throwable,子类有Error和Exception. 其中Error的异常是系统崩溃或者数据库崩溃导致的,Exception的异常是有程序代码的异常导致的 Exception的有很多子类我们常见的有三类:空指针(NullPointerExcep

HKDxiaofan的博客 698

极智芯 | 解读国产CPU之海光

大家好,我是极智视界,本文分享一下 解读国产CPU之海光。希望我的分享能对你的学习有一点帮助。

极智视界 3316

报错:java.lang.ArrayIndexOutOfBoundsException——数组越界

题目: 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组. class Solution { public int removeDuplicates(int[] nums) { int count=nums.length; for(int i=0;i<co...

枫林晚的博客 15万+

基于生存结局(生存分析/COX回归)的中介效应分析

① 建立观察变量OVB和中介变量MVB的回归模型(注意:这里根据mediation包的介绍,需要构建的是probit模型,而不是logist回归模型,网上有很多的代码用的logistic回归,结果自己跑的时候发现报错,我在这里陷了很久;为了方便演示,我们生成了一个协变量(Age)、一个连续型观察变量(liaOVC)、一个二分类观察变量(OVB)、一个连续型中介变量(MVC)、一个二分类中介变量(MVB)以及最后的结局变量(生存时间[time],生存结局[stats])。

m0_61863309的博客 1万+

以阿克曼转向车为例对URDF和XACRO文件进行解读

   最近我在古月学院购买了在Gazebo中实现阿克曼转向车的仿真课程,课程资料的阿克曼小车的XACRO文件在Gazebo里加载的时候报了三个错误,在这之前,我没接触过URDF或XACRO文件,本篇文章就以这个阿克曼小车的XACRO文件为例,对URDF或XACRO文件的格式和内容进行解读,期望经过解读和学习,找到错误原因及所在,并解决这三个错误    先来放一下上面右图所示的模型的完整的XACRO文件: <?xml version="1.0"?> <!-- racecar.urdf.x

慕羽★的博客 3700

解决java.lang.IndexOutOfBoundsException: Index: 0, Size: 0的问题

出现这种问题是数组值没有取到,解决办法如下: 如:List orgList=sysOrgService.getByUserId(su.getUserId());             String orgName="";             if (orgList!=null&&orgList.size()>0) {                                 o

cxws110的博客 16万+

Week 9 10 Neural Networks

Week 9 10 Neural Networks

金州饿霸吃不饱的博客 402

Java自定义Exception设计

         本文讨论有关异常设计的问题,关注何时和怎么更好的使用异常类,设计符合自己系统的自己定义异常类。这里假设读者已经对java已经一定的了解,知道什么是java的异常,及其工作原理。读者想了解java 和 java异常相关知识,请拜读《Thinking in java 3rd 》(真实一本好书^_^)异常设计原则:       异常表示没有遵守契约。如果一个事件表示了“异常

或许我已经死去,只是没注意到罢了! 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Java自定义Exception

本篇博客是Java Exception类的一个简单总结,并实现了一个自定义Exception类

Triangle23 2014

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

C#_自定义Exception

  自定义Exception,并且能捕捉到。 网上搜的估计都是一样的,不如自己写一个,需求是返回错误信息和返回一个自定义的List   定义 xxxxException.cs using System; using System.Collections.Generic; public class DeliveryProgressException : Exception { ...

Martin 的博客 3143

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

在java中允许用户自定义异常_Java自定义Exception

这里总结一下Java的Exception,并实现一个自定义Exception类。总结:Throwable对象分为两种类型:Error(表示编译时和系统错误);Exception(在Java类库、用户方法以及运行时故障中抛出的异常)。Exception细分成两种异常:受检查异常(如,IOException, SQLException等。在编译时要被强制检查的异常,需要用try, catch, fin...

weixin_30925033的博客 368

自定义异常应该继承Exception还是继承RuntimeException

一、前言 在实际开发中,常常写的代码需要抛出异常,抛出的异常需要使用到自定义异常,这个时候定义自定义异常需要考虑到是继承Exception还是RuntimeException。 二、Throwable类图 exception异常分为:受查异常、非受查异常。 受查异常需要进行try-catch,非受查异常则不需要。 受查异常: IOException、classNotFund 非受查异常又被称为:RuntimeException 三、使用场景 继承了Exception也就是定义为受查异常,则需要在使用者进行

路漫漫其修远兮 吾将上下而求索 4212

Java自定义异常,应该继承Exception还是Runtime Exception,为什么?

回答1: 继承Exception还是继承RuntimeException是由异常本身的特点决定的,而不是由是否是自定义的异常决定的。 例如我要写一个java api,这个api中会调用一个极其操蛋的远端服务,这个远端服务经常超时和不可用。所以我决定以抛出自定义异常的形式向所有调用这个api的开发人员周知这一操蛋的现实,让他们在调用这个api时务必考虑到远端服务不可用时应该执行的补偿逻辑(比如尝试调用另一个api)。此时自定义的异常类就应继承Exception,这样其他开发人员在调用这个api时就会收到编

AlbenXie的博客 5167

自定义Exception异常

自定义异常构建 首先写一个自定义异常,继承Exception,代码如下 public class NoMappingParamString extends Exception { /*无参构造函数*/ public NoMappingParamString(){ super(); } //用详细信息指定一个异常 ...

weixin_34044273的博客 224

Java异常讲解并自定义Exception异常

Exception和Error有什么区别? 典型回答 Exception和Error都是继承了Throwable类,在Java中只有Throwable类型的实例才可以被抛出(throw)或者捕获(catch),它是异常处理机制的基本组成类型。 Exception和Error体现了Java平台设计者对不同异常情况的分类。Exception是程序正常运行中,可以预料的意外情况,可能并且应该被捕获,进行相应处理。 Error是指在正常情况下,不大可能出现的情况,绝大部分的Error都会导致程序(比如JVM自身)处

an_zzzzz的博客 601

Exception四 自定义异常

自定义异常 创建一个自定义异常的类继承Exception 重构两个方法,一个有参数,一个无参数: 代码举例: public class Demo10DefinedException extends Exception{ public Demo10DefinedException() { } public Demo10DefinedException(String message) { s...

tangshuai96的博客 314
上一篇: 清理和删除svn信息
下一篇: Exception 自定义
MyJavaBlog
博客等级 码龄16年 11粉丝 126原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值