throws

SocketIO---Netty--HelloWorld

大城市里の小女人 提交于 2019-11-28 23:32:47
1. server 1 public class Server { 2 3 public static void main(String[] args) throws Exception { 4 System.out.println("Server is starting..."); 5 //1 创建线两个程组 6 EventLoopGroup bossGroup = new NioEventLoopGroup(); //一个是用于处理服务器端接收客户端连接的 7 EventLoopGroup workGroup = new NioEventLoopGroup(); //一个是进行网络通信的(网络读写的) 8 9 //2 创建辅助工具类,用于服务器通道的一系列配置 10 ServerBootstrap b = new ServerBootstrap(); 11 b.group(bossGroup, workGroup) //绑定俩个线程组 12 .channel(NioServerSocketChannel.class) //指定NIO的模式 13 .option(ChannelOption.SO_BACKLOG, 1024) //设置tcp缓冲区 14 .option(ChannelOption.SO_SNDBUF, 32*1024) //设置发送缓冲大小 15 .option

throw与throws的区别

依然范特西╮ 提交于 2019-11-28 22:41:19
throw与throws的区别 1.throw是在方法内部的代码块中,手动异常抛出 2.throws是在方法定义时用 举例如下 1、手动抛出–throw public class Hello { public static void main(String[] args) { try { throw new Exception("手动抛出的异常"); }catch(Exception e) { e.printStackTrace(); } } } 2、方法定义时–throws class Text{ public static int div(int x,int y) throws Exception{ return x/y; } } public class Hello { public static void main(String[] args) { try { System.out.println(Text.div(12, 0)); }catch(Exception e) { e.printStackTrace(); } } } 来源: https://blog.csdn.net/weixin_39537054/article/details/100144384

Day24 IO流---转换流和缓冲流

十年热恋 提交于 2019-11-28 20:40:14
一、转换流 将字节流转换为字符流,来操作文本文档 转换流可以设定制定编码表 1、构造方法 (将字节输入流转为字符输入流) (将字节输出流转为字符输出流) (常用方法就是字符流的常用方法) public class ReaderTest { public static void main ( String [ ] args ) throws IOException { InputStreamReader isr = new InputStreamReader ( new FileInputStream ( "D:\\test\\c.txt" ) ) ; int read = isr . read ( ) ; System . out . println ( ( char ) read ) ; } } public class ReaderTest { public static void main ( String [ ] args ) throws IOException { OutputStreamWriter isw = new OutputStreamWriter ( new FileOutputStream ( "D:\\test\\b.txt" , true ) ) ; String s = "hahahaha" ; isw . write ( s ) ; isw .

Try-with-resources

南楼画角 提交于 2019-11-28 19:50:33
资源管理与 Try-Catch-Finally,旧风格 在 java 7 之前,管理需要明确关闭的资源是相当繁琐的。 看看下面的方法,它读取一个文件并将其打印到 System.out 中: private static void printFile() throws IOException { InputStream input = null; try { input = new FileInputStream("file.txt"); int data = input.read(); while(data != -1){ System.out.print((char) data); data = input.read(); } } finally { if(input != null){ input.close(); } } } 在上面的代码中有四处可能抛出异常 new FileInputStream("file.txt"); 、 int data = input.read(); 、 data = input.read(); 、 input.close(); 。 不管 try 块是否抛出异常, finally 块总是被执行。也就是说,无论 try 快种发生了什么, InputStream 都将被关闭。然而如果关闭失败, close() 方法也有可能抛出异常。 思考一下,如果

基于Java+Selenium的WebUI自动化测试框架(九)-----基础页面类(BasePage)

落花浮王杯 提交于 2019-11-28 19:48:38
  上篇我们写了java读取xml文件的类,实现了可以从xml文件读取元素的方式。那么,接下来我们需要考虑一个问题。我们拿了这些元素之后怎么去操作呢?   先来看看我们手工测试的时候是怎么进行的。   双击浏览器,打开网站(浏览器初始化),然后在打开的网页上进行一些操作(比如输入,点击什么的)。假如,我们根据每个页面来写一个类,这样的话如果有几百个页面,我们就要封装几百个类,这样做也是非常的麻烦和复杂!,也不利于自动化脚本的维护。   进一步想想,其实我们在每个页面上所做的操作也就那么几种。(输入文字,点击,得到某元素的文字,查看某元素是否显示,切换frame,切换窗口,处理弹窗等等。)根据这些页面上操作的共性,我们可以设计一个基础页面类,使用这个基础页面类来对各个具体的页面进行实例化。那么基础页面类中的方法,我们就可以在实例化的具体页面中进行调用。   由于目前我们只写了读取XML的类。因此,我们就先写一个支持XML读取的基础页面类。 package webui.xUtils; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; import java.util.HashMap; import org.openqa.selenium.WebDriver;

MyBatis基础-CRUD

白昼怎懂夜的黑 提交于 2019-11-28 19:19:35
一、mybatis 环境搭建步骤  第一步:创建 maven 工程 第二步:导入坐标 第三步:编写必要代码(实体类和持久层接口) 第四步:编写 SqlMapConfig.xml 第五步:编写映射配置文件 第六步:编写测试类 二、编写sqlMapConfig.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <!-- 主配置文件 --> <configuration> <!-- 配置环境 --> <environments default="mysql"> <environment id="mysql"> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/eesy_mybatis"/>

What are the differences between throws and rethrows in Swift?

我的未来我决定 提交于 2019-11-28 16:59:28
问题 After searching for some references to figure it out, -unfortunately- I could not find useful -and simple- description about understanding the differences between throws and rethrows . It is kind of confusing when try to understand how we should use them. I would mention that I am kind of familiar with the -default- throws with its simplest form for propagating an error, as follows: enum CustomError: Error { case potato case tomato } func throwCustomError(_ string: String) throws { if string

Is there a way to make Runnable's run() throw an exception?

江枫思渺然 提交于 2019-11-28 16:47:49
A method I am calling in run() in a class that implements Runnable ) is designed to be throwing an exception. But the Java compiler won't let me do that and suggests that I surround it with try/catch. The problem is that by surrounding it with a try/catch I make that particular run() useless. I do want to throw that exception. If I specify throws for run() itself, the compiler complains that Exception is not compatible with throws clause in Runnable.run() . Ordinarily I'm totally fine with not letting run() throw an exception. But I have unique situation in which I must have that functionality

java基础——异常

若如初见. 提交于 2019-11-28 16:12:55
Exception(异常):是程序本身可以处理的异常。Exception 类有一个重要的子类 RuntimeException。RuntimeException 类及其子类表示“JVM 常用操作”引发的错误。例如,若试图使用空值对象引用、除数为零或数组越界,则分别引发运行时异常(NullPointerException、ArithmeticException)和 ArrayIndexOutOfBoundException。 Exception(异常)分两大类:运行时异常和非运行时异常(编译异常)。程序中应当尽可能去处理这些异常。 1.运行时异常:都是RuntimeException类及其子类异常,如NullPointerException(空指针异常)、IndexOutOfBoundsException(下标越界异常)等,这些异常是不检查异常,程序中可以选择捕获处理,也可以不处理。这些异常一般是由程序逻辑错误引起的,程序应该从逻辑角度尽可能避免这类异常的发生。运行时异常的特点是Java编译器不会检查它,也就是说,当程序中可能出现这类异常,即使没有用try-catch语句捕获它,也没有用throws子句声明抛出它,也会编译通过。 2.非运行时异常 (编译异常):是RuntimeException以外的异常,类型上都属于Exception类及其子类。从程序语法角度讲是必须进行处理的异常

Function throws AND returns optional.. possible to conditionally unwrap in one line?

◇◆丶佛笑我妖孽 提交于 2019-11-28 13:42:27
I am using an SQLite library in which queries return optional values as well as can throw errors. I would like to conditionally unwrap the value, or receive nil if it returns an error. I'm not totally sure how to word this, this code will explain, this is what it looks like: func getSomething() throws -> Value? { //example function from library, returns optional or throws errors } func myFunctionToGetSpecificDate() -> Date? { if let specificValue = db!.getSomething() { let returnedValue = specificValue! // it says I need to force unwrap specificValue, // shouldn't it be unwrapped already? let