Java Custom Exceptions

Source: Internet
Author: User

Package com.eshore.ismp.pay.common.exception, @SuppressWarnings ("Serial") public class Payexception extends exception {private int exceptionid;//error code private String info;//error message public payexception (int exceptionid, String info) {super (); Exceptionid = Exceptionid;this.info = info;} Public payexception (Int. exceptionid) {Exceptionid = Exceptionid;} public payexception (String info) {super (info); This.info = info;} Public String toString ()    {        return (new StringBuilder ()). Append ("Payexception,code="). Append (Exceptionid). ToString ();    } Public String GetInfo () {return info,} public int Getexceptionid () {return exceptionid;} public static Byte INTERNAL =-2; Internal error public static byte mdb_internal = -6;//Database Error}

Need to inherit exception class

Then a class is going to use this exception class first throws Exception

And then

} catch (HttpException e) {throw new Payexception (Payexception.internal,e.getmessage ());} catch (IOException e) { Postmethod.releaseconnection ();//Consider long connections? Simplehttpconnectionmanager connm = (Simplehttpconnectionmanager) Httpclient.gethttpconnectionmanager (); Connm.closeidleconnections (0); throw new Payexception (Payexception.internal,e.getmessage ());

Similar to the above, so that we can determine where the problem is due to the error code thrown.

Java Custom Exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.