Throwable类toString()方法 (Throwable Class toString() method)

  • toString() Method is available in java.lang package.

    toString()方法在java.lang包中可用。

  • toString() Method is used to return a short description of the exception.

    toString()方法用于返回对该异常的简短描述。

  • toString() Method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    toString()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • toString() Method does not throw an exception at the time of string representation about the exception.

    toString()方法在有关异常的字符串表示时不会引发异常。

Syntax:

句法:

    public String toString();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is String, it represents string for the exception.

方法的返回类型为String ,它表示异常的字符串。

Example:

例:

// Java program to demonstrate the example
// of String toString() method of Throwable
public class ToString {public static void main(String args[]) throws Exception {try {div(-3, 0);
} catch (Exception ex) {System.out.println("ex.toString() :" + ex.toString());
}
}
// This method divide number by 0
public static void div(int d1, int d2) throws Exception {int res = d1 / d2;
System.out.println("res :" + res);
}
}

Output

输出量

ex.toString() :java.lang.ArithmeticException: / by zero

翻译自: https://www.includehelp.com/java/throwable-tostring-method-with-example.aspx

Java Throwable toString()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. Java之toString()方法详解

    Java之toString()方法详解 Java中 toString()方法在Object类中和Intent类中都有定义,作用类似,但显示形式有点区别 一.Object类中toString()方法 t ...

  3. java Boolean toString()方法

    java Boolean toString()方法 声明 public static String toString(boolean b) 返回值 返回指定布尔值的字符串表达形式 /*** Creat ...

  4. Java调用tostring方法分析_Java对象toString()方法

    对象的字符串表示以可读格式包含有关对象状态的信息. Object类的toString()方法表示字符串中类的对象.Object类提供了toString()方法的默认实现. 它返回一个以下格式的字符串: ...

  5. JAVA中toString方法的作用(转)

    因为它是Object里面已经有了的方法,而所有类都是继承Object,所以"所有对象都有这个方法". 它通常只是为了方便输出,比如System.out.println(xx),括号 ...

  6. [转载] java重写toString()方法

    参考链接: 在Java中重写toString() 前言: 在你兴高采烈的写完一个类,创建测试类时,创建对象,传入参数,调用对象,以为会得到参数值,但突然发现输出的是" 类名@什么东东?(其实 ...

  7. JAVA基础——toString()方法,java基础面试笔试题

    我总结出了很多互联网公司的面试题及答案,并整理成了文档,以及各种学习的进阶学习资料,免费分享给大家. 扫描二维码或搜索下图红色VX号,加VX好友,拉你进[程序员面试学习交流群]免费领取.也欢迎各位一起 ...

  8. JAVA中toString方法的作用

    一句话概括:就是可以把实体类,或者其他类,以字符串或者规定的方式输出, 如果用了toString那么就会这样输出User 否则就会输出: 因为它是Object里面已经有了的方法,而所有类都是继承Obj ...

  9. java list的tostring,Java ArrayList toString() 方法

    toString() 方法将 Arraylist 对象转换为字符串. 语法 toString() 方法的语法为: arraylist.toString() 注:arraylist 是 ArrayLis ...

最新文章

  1. 12月第四周安全回顾:双节期间微软忙补新漏洞,新Hash将测试
  2. 2017.0612.《计算机组成原理》总线结构
  3. java 树 右键菜单_jQuery实现自定义右键菜单的树状菜单效果
  4. linux部署jar项目报错_Spring boot项目部署linux系统tomcat报错解决办法
  5. 解决svn cannot set LC_CTYPE locale的问题
  6. 无损连接性、保持函数依赖1
  7. 2018华为笔试题2
  8. 傅里叶光学导论_激光位移传感器的光学系统设计
  9. STM8L051低功耗实现
  10. 流媒体 直播细节优化
  11. 获取本地视频url的方法
  12. java 一元二次方程_java求解一元二次方程
  13. matlab特征值分解
  14. 人的精力是什么?如何强化精力
  15. 青岛科技大学计算机学院官网,青岛科技大学
  16. VBA-EXCEL:控制WORD指定位置,插入图片并调整在大小,高低,环绕
  17. shiro使用Md5加密
  18. MG90S舵机驱动原理和程序代码
  19. 苹果截屏快捷键_苹果手机有哪些便捷的实用技巧?果粉们都在使用这些技巧,你会吗...
  20. 台达JAVA_java开发方向面试-台达电子-数码视讯

热门文章

  1. linux桌面时区设置,如何在Ubuntu 20.04上设置或更改时区
  2. mysql存储map数据结构_map数据结构
  3. 360手柄摇杆漂移修复_彻底解决你的Switch手柄摇杆问题,最省钱的完美修复。
  4. 【Java从入门到头秃专栏 6】语法篇(五) :多线程 线程池 可见、原子性 并发包 Lambda表达式
  5. 公司台湾主站的url重写
  6. Linux升级内核的正确姿势
  7. RAID阵列基础知识
  8. 对github的初步认识以及对软件技术基础课程的期待
  9. 为何有些程序员总是想要“干掉”产品经理?
  10. maven插件介绍之tomcat7-maven-plugin