zoukankan      html  css  js  c++  java
  • Java笔记 #01# 最近遇到的几个Throwable

    《Java入门第三季》第一章 异常与异常处理

     1、StackOverflowError

     第一次碰到这个 Error 居然有点小激动,原因当然是因为它叫 StackOverflow

    Q:What is a StackOverflowError, what causes it, and how should I deal with them? (选择性 COPY)

    The common cause for a stack overflow is a bad recursive call. Typically, this is caused when your recursive functions doesn't have the correct termination condition, so it ends up calling itself forever. However, with GUI programming, it's possible to generate indirect recursion. For example, your app may be handling paint messages, and, whilst processing them, it may call a function that causes the system to send another paint message. Here you've not explicitly called yourself, but the OS/VM has done it for you.
    
    To deal with them you'll need to examine your code. If you've got functions that call themselves then check that you've got a terminating condition. If you have then check than when calling the function you have at least modified one of the arguments, otherwise there'll be no visible change for the recursively called function and the terminating condition is useless.

    --Sean  总而言之,出现这种错误一般是递归调用没处理好。个人是因为 DAO 层和 Service 层恰好有相同接口,然后一不小心把 Service 层代码无限递归调用了,(本意是调用 DAO.getFriends 然后写成 getFriends 。。。)

    2、java.io.StreamCorruptedException: invalid type code: AC

    http://ask.csdn.net/questions/10152

    今天在用套接字编程是遇到java.io.StreamCorruptedException: invalid type code: AC
    遇到这个异常时候很茫然,最后在别人的google的帮助下,最后还是找出了错误所在,这是因为一个线程中定义了多个objectOutputStream,为什么不允许定义多个就不清楚了,其他outputStream是可以定义多个的。
    如果前面已经初始化了这objectOutputStream对象,以后在使用它时,最好使用参数引用

    一般而言,就是由于在一个或者多个线程里创建多个同源outputStream。

    3、java.io.StreamCorruptedException: invalid stream header: 54657374

     

    标题是网上找的,我遇到的是图上这个,网上的资料有点乱,反正我是这样解决的:起因(大概)是由于一个 socket 在多个线程开 inputStream ,可能偶尔有些线程自动被回收了,偶尔没有。(所以这个异常隐蔽性还是很高的?)

  • 相关阅读:
    webpack 入门(1)入口(entry)出口(output
    npm 常用使用命令
    typora快捷键
    一些思考
    SED LEARN NOTE
    常用网站工具整理
    DFTC
    Notion使用技巧
    BASH LEARN NOTE
    STBC公式
  • 原文地址:https://www.cnblogs.com/xkxf/p/8257412.html
Copyright © 2011-2022 走看看