Simple and clear. Your tutorials are very helpful. Thank you so much mate. Blessings at you 🙏🏼
@rashedahmed63392 жыл бұрын
Your tutorials are very helpful. You're a legend.
@gaurav12525 жыл бұрын
perfect! bro can u plz make an ebook of dart and flutter... its very helpful to refer stuffs quickly... thanks!:)
@hicnar5 жыл бұрын
I think one important concept is missing here. You do not address how to differently handle different types of exceptions in multiple catch blocks corresponding to the same "try" also what happens if the custom exception caught does not implement the errorMessage( ) method as in your example (and if that's the case you will get noSuchMethod exception thrown from within the catch block). try { // code throwing different types of exceptions } on DepositException catch (e) { // a typed exception handled here, safe access to all methods and fields it actually implements/defines without the risk of noSuchMethod being thrown } on SecurityException catch (e) { // another exception type handled here, and similarly access to all methods and fields it actually implements/defines }
@zeusking4468 Жыл бұрын
correct !
@Wongmc6442 жыл бұрын
great tutorial but doesn't work with latest dart version! I'm learning a lot from this tutorial. i tried and manage to get it working as below codes, sharing & hope it can help others.. ============== void main() { print('case 5'); try { depositMoney(-200); } catch (e) { print(e.toString()); } } class DepositException implements Exception { @override String toString() { //return errorMessage(); return ('you cannot enter amounts < zero'); } // method not needed, return text direct from overridden method toString() // only need to override toString method from super class Exception to //return error text // return ('you cannot enter amount < 0'); // } } void depositMoney(int amount) { if (amount < 0) { throw DepositException(); } } ==============
@vighneshsharma2 жыл бұрын
FOR THOSE WHO ARE FACING PROBLEM WIITH NEW DARTPAD SDK You can also implement toString() in the exception so you can call its message with e.toString(). so the code will be void main(){ try{ depositMoney(-200); } catch (e){ print(e.toString()); } } class DepositException implements Exception{ String toString() => "you cannot enter amount less than 0"; } void depositMoney(int amount){ if(amount < 0){ throw DepositException(); } } //goodluck
@jayednahian14052 жыл бұрын
thats nice without using the specific function name ! i came up with a conclusion too !.. try { depositMoney(-200); } catch (e) { print(DepositException().errorMessage()) }
@labeeb29032 жыл бұрын
try{ depositAmount(-100); } on DepositException catch (e){ print(e.errorMessage()); }
@eainsworld4864 Жыл бұрын
Thank you so much.
@gamersguildboxbreaks90632 ай бұрын
I literally don't understand but it worked Pls can I get your Instagram or WhatsApp number so you can explain better to me pls Thanks
@soonclass42695 жыл бұрын
You can also implement toString() in the exception so you can call its message with e.toString() import 'package:flutter/material.dart'; class InternalServerException implements Exception { final String msg; InternalServerException({@required this.msg}); String errorMessage() { return msg; } @override String toString() => msg; }
@syednokhaizalhassan18003 жыл бұрын
class CustomException implements Exception { String cause; CustomException(this.cause); String errorMessage() { return cause; } } void throwException(int amount) { if (amount < 0) { throw new CustomException("The amount less than zero not acceptable"); } } void main() { try { throwException(-200); } on CustomException catch (e) { print(e.errorMessage()); } }
@rifatmehedi20825 жыл бұрын
Sir... Please connect charger with your laptop... only 11% charge available. Thanks for your nice videos anyway:)
@smartherd5 жыл бұрын
Haha
@rahulsrinivas10044 жыл бұрын
chutiya
@saisasisai4 жыл бұрын
Nice 👌 Tutorial series ...!
@abhaythakur85725 жыл бұрын
you said at 1:15 Exception is a Class in dart if it is a class then you should use extends keyword as i know we use implements keyword with interface please clear my doubt
@__shubham__3 жыл бұрын
Sir please help, in new update of Dart SDK V2.12.1 String errorMessage() is impeding the program to run, saying *The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. Try adding either a return or a throw statement at the end.* Also it says _The method 'errorMessage' isn't defined for the type 'Object'. Try correcting the name to the name of an existing method, or defining a method named 'errorMessage'_ . Edit : _Actually in new version i.e. V2.12.1 and above , null string is no longer supported_ . you can't do *String* name ; // _initially null_ So now one has to write *String* name = "name"; // _some default name initially that can be renamed later_
@shreyashkashyap2 жыл бұрын
Unable to access errorMessage() from main(). It shows - The method 'errorMessage' isn't defined for the type 'Object'. Try correcting the name to the name of an existing method, or defining a method named 'errorMessage'.
@mayankgarg97282 жыл бұрын
yes please tell; and the error is logically right too as without creating an object of class how can you directly call its function?
@jayednahian14052 жыл бұрын
@@mayankgarg9728 i think " throw new DepositException();" line of helps to create the object
@parikumari70042 жыл бұрын
You have solution for this question, i am facing same problem plzz help?
@subhamkrpaul10342 жыл бұрын
Try this code, Happy coding: void main() { try { throwException(-200); } on CustomException catch (e) { print(e.errorMessage()); } } class CustomException implements Exception { String cause; CustomException(this.cause); String errorMessage() { return cause; } } void throwException(int amount) { if (amount < 0) { throw CustomException("The amount less than zero not acceptable"); } }
@psychopath43512 жыл бұрын
thanks bro. you saved my day!
@ripudhman7355 Жыл бұрын
Thanks 🙏
@MohamedDernoun4 жыл бұрын
hi @Smartherd, is there a way to make a custom Exception where i add only a string -that help to identify the place of exception on the program- to the existing Exception
@nolssmit Жыл бұрын
The example in the video gives errors with Dart version 3+ The new example: void main() { try { depositMoney(-200); } on DepositException catch (e) { print(e.errorMessage()); } } class DepositException implements Exception { String cause; DepositException(this.cause); String errorMessage() { return cause; } } void depositMoney(int amount) { if (amount < 0) { throw new DepositException("The amount less than zero not acceptable"); } }
@redpersimmon6940 Жыл бұрын
Thankyou So Much 👍
@muazbhatti413 жыл бұрын
great information in this section.
@shaaficialli42844 жыл бұрын
what is implement idon`t understanding this when you give name class and then class name idon't know where implements and exception comes from please help me
@AztechZone13 жыл бұрын
indeed it is an intersting lecture
@sushantprajapati17045 жыл бұрын
What is the difference in 'throw new' and just using 'throw'? Could you please help me with my confusion!
@vibhor13862 жыл бұрын
what's rethrow?
@ekshivbhakt24176 жыл бұрын
errormessage has no return value, can we use string type if there is no return statement??
@ziasultan81575 жыл бұрын
How do you accessed to depositMoney() from main method Program says depositMoney() is not defined
@saad-rc8mn3 жыл бұрын
I am trying a same code but in output show a error why? Error: The method 'errorMessage' isn't defined for the class 'Object'. - 'Object' is from 'dart:core'. Try correcting the name to the name of an existing method, or defining a method named 'errorMessage'. print(e.errorMessage());
@Anonymous-ig5nm3 жыл бұрын
Same for me also how to debug it
@dibyodhara43262 жыл бұрын
try { depositMoney(-200); } on DepositException catch(e) { print(e.errorMessage()); }
@parikumari70042 жыл бұрын
@@dibyodhara4326 nice , thanks
@ritwikrajsingh34203 жыл бұрын
Few things are outdated now, please try to fix them, it'll help alot
@thefossenjoyer33462 жыл бұрын
Yeah, this is outdated. Weird how much a language can change in 4 years. xD
@ritwikrajsingh34202 жыл бұрын
@@thefossenjoyer3346 Google is trying to make a mess instead of convenience.
@thefossenjoyer33462 жыл бұрын
@@ritwikrajsingh3420 ah yes.
@arnabdeb14863 жыл бұрын
dartpad shows the method 'errorMessage' isn't defined for the type object
@dineshbhavsar14353 жыл бұрын
Same Daut me
@georgerassovsky37333 жыл бұрын
Had the same problem. This works for me: try { depositMoney(-200); } on DepositException catch (e) { print(e.errorMessage()); }
@davestr20466 жыл бұрын
Perfect!
@cybernerd74923 жыл бұрын
nice vid
@coffeeCatPeanutDust2 жыл бұрын
The code in this video unfortunately no longer seems to work
@raptorrogue42278 ай бұрын
This doesnt work on dartpad 😓
@bivu89516 жыл бұрын
Cant understand -- "implements Exception"
@smartherd6 жыл бұрын
Continue watching. U will get to know what it is
@jesssinues4156 жыл бұрын
@0:32 Thank me later.
@md.soleymankhan65503 жыл бұрын
Do not know why that code is not running. But this worked: class DepositException implements Exception{ String errorMessage() => "you can not add amount less then 0"; } void main(){ int amount = -200; try { depositMoney(amount); }catch(e){ print(e.errorMessage()); } } void depositMoney(int amount){ if(amount