This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
class LoginPage extends Vue { | |
// ... | |
loginUser() { | |
api.loginUser(this.email, this.password) | |
.then(handleLogin) | |
.catch(error => Toast.error(error.message)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
class LoginPage extends Vue { | |
// ... | |
async loginUser() { | |
try { | |
const token = await api.loginUser(this.email, this.password) | |
handleLogin(token) | |
} catch(error) { | |
Toast.error(error.message) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
class LoginPage extends Vue { | |
// ... | |
async loginUser() { | |
try { | |
const token = await api.loginUser(this.email, this.password) | |
handleLogin(token) | |
} catch(error) { | |
Toast.error(error.message) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main.js | |
Vue.config.errorHandler = function (error) { | |
Toast.error(error.message) | |
console.warn(error.message) | |
} | |
// App.vue | |
@Component | |
export default class App extends Vue { | |
async created() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
class App extends Vue { | |
// ... | |
decodeData(data) { | |
try { | |
this.decodedData = atob(data) // can throw DOMException | |
} catch(error) { | |
Toast.error(error.message) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
public static void main(String[] args) throws IOException { | |
FileReader file = new FileReader("C:\\test\\a.txt"); | |
// ... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// register global handler | |
catchDecorator.register((error) => Toast.error(error.message)) | |
@Component | |
class LoginPage extends Vue { | |
// ... | |
// catch errors and run global handler | |
@Catch() | |
async loginUser() { | |
const token = await api.loginUser(this.email, this.password) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function log(func) { | |
return function() { | |
func() | |
console.log('Function called') | |
} | |
} | |
function getData() { ... } | |
getData = log(getData) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Catch(target, key, descriptor) { | |
const originalMethod = descriptor.value | |
descriptor.value = async function(...args) { | |
try { | |
return await originalMethod.apply(this, args) | |
} catch (error) { | |
console.warn(error.message) | |
Toast.error(error.message) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Catch from './catchDecorator' | |
@Component | |
export default class App extends Vue { | |
@Catch | |
async created() { | |
const data = await api.getData() // throws Error | |
} | |
@Catch |