简体   繁体   中英

How is the error message initialized when an exception is thrown?

There is a String object called detailMessage in java.lang.Throwable class, which says the reason of any exception thrown in java code.

This object is initialized through a constructor using super(string message) statement or setter or whatever from subclasses like Exception and again from its subclasses like SQLException.

When SQLException is thrown, error message can be displayed using sqlExceptionObject.getMessage();

The error message in sqlExceptionObject.getMessage() is same as in MySQL tool (Incase of any error in query execution)

So is the error message copied from MySQL? If yes, then from where?

The JDBC driver is responsible for that. It could translate an error code it gets from the DB to a string or it could get the error string directly from the DB. I don't know which one is the case for MySQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM