3.8.自定义异常

一.自定义异常操作步骤:

1.定义异常类:类名要见名知意。起名->异常的名字+Exception

2.写继承关系:a.运行时异常,继承RuntimeException;

b.编译时异常,继承Exception

3.写空参构造

4.写带参构造

自定义异常的目的(意义):就是为了让控制台的报错信息更加的见名知意。

以上两个构造方法(应译为Constructor)可用快捷键alt+fn+ins可快速生成

步骤"alt+fn+ins->构造方法->选择要加入的方法即可"

二.举例:

比如之后调用setName方法,若异常,则执行if里的语句。

TypeError: Cannot read property &#39;reading_light_on&#39; of undefined at success (app.js? [sm]:27) at Object.success (WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1) at Object.success (WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1) at Function.I.forEach.v.<computed> (WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1) at :15910/appservice/<api request success callback function> at WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 at Nu (WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1) at Function.<anonymous> (WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1) at :15910/appservice/<NetworkRequest15success callback function> at WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1(env: Windows,mp,1.06.2301160; lib: 3.8.11) errorReport @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 thirdErrorReport @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 p @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 Nu @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 p @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 Bm @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 emit @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 u @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 tb @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 _emit @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 emit @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 c @ VM23 asdebug.js:10 (anonymous) @ VM23 asdebug.js:10 a.emit @ VM23 asdebug.js:1 callback @ VM23 asdebug.js:10 (anonymous) @ VM23 asdebug.js:10 setTimeout (async) h @ VM23 asdebug.js:10 n @ VM23 asdebug.js:10 O.onreadystatechange @ VM23 asdebug.js:10 XMLHttpRequest.send (async) v @ VM23 asdebug.js:10 createRequestTask @ VM23 asdebug.js:10 invoke @ VM23 asdebug.js:10 r @ VM23 asdebug.js:10 invoke @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 pn @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 Up @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 Y_ @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 Q_ @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 u @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 J_ @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 yM @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 createRequestTask @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 execute @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 tct @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 I @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 p @ WAServiceMainContext.js?t=wechat&s=1752416301351&v=3.8.11:1 p @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 value @ apihook.js?t=wechat&s=1752416301351&v=0cffbba9918afb1342c18e2fdfb25ef5:1 onLaunch @ app.js? [sm]:20 (anonymous) @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 Rt @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ app.js? [sm]:3 (anonymous) @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 runWith @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 q @ WASubContext.js?t=wechat&s=1752416301351&v=3.8.11:1 (anonymous) @ VM513:7 doWhenAllScriptLoaded @ VM494:1342 (anonymous) @ VM494:15 loadBabelModules @ assubloader.js:1 async function (async) loadBabelModules @ assubloader.js:1 window.loadBabelMod @ VM449:10 (anonymous) @ toConsumableArray.js:2 Show 32 more frames WAServiceMainC
07-14
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值